import java.sql.DriverManager
import java.sql.SQLExceptionpublic 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了
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)