package db;
import java.sql.DriverManager;
import java.sql.SQLException;
import com.mysql.jdbc.Connection;
public class DBConnection {
private String dbDriver="com.mysql.jdbc.Driver";
private String dbUrl="jdbc:mysql://localhost:3306/db_student?useUnicode=true&characterEncoding=GB2312";
private String dbUser = "root";
private String dbPwd = "123456";
public Connection getConn(){
Connection conn=null;
try {
Class.forName(dbDriver);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
conn=(Connection) DriverManager.getConnection(dbUrl, dbUser, dbPwd);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return conn;
}
}
java连接mysql封装类
最新推荐文章于 2021-02-12 18:17:01 发布