1,首先寫個方法package util;import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;public class DBUtil { static String jdbcURL = "jdbc:mysql://localhost:3306/book";
static String jdbcDriver = "com.mysql.jdbc.Driver";
static String userName = "root";
static String password = "root";
/**
* 獲取資料庫連線物件
* @return 資料庫連線物件
* @throws ClassNotFoundException
* @throws SQLException
*/
public static Connection getConnection() throws ClassNotFoundException,
SQLException {
Class.forName(jdbcDriver);
return DriverManager.getConnection(jdbcURL, userName, password);
}
} 2。專案名==>右鍵==>build path==>add external archivers.... 選擇你mysql驅動 新增進去就ok了
1,首先寫個方法package util;import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;public class DBUtil { static String jdbcURL = "jdbc:mysql://localhost:3306/book";
static String jdbcDriver = "com.mysql.jdbc.Driver";
static String userName = "root";
static String password = "root";
/**
* 獲取資料庫連線物件
* @return 資料庫連線物件
* @throws ClassNotFoundException
* @throws SQLException
*/
public static Connection getConnection() throws ClassNotFoundException,
SQLException {
Class.forName(jdbcDriver);
return DriverManager.getConnection(jdbcURL, userName, password);
}
} 2。專案名==>右鍵==>build path==>add external archivers.... 選擇你mysql驅動 新增進去就ok了