private String dburl = "jdbc:mysql://localhost:3306/db_library";
private String dbuserName = "root";
private String dbpassword = "123456";
private String jdbcName = "com.mysql.jdbc.Driver";
public Connection getcon() throws ClassNotFoundException, SQLException{
Class.forName(jdbcName);
Connection con=DriverManager.getConnection(dburl,dbuserName,dbpassword);
return con;
}
public void closeCon(Connection con) throws SQLException{
if(con!=null){
con.close();
}
}
dburl的最后一定要换成自己的数据库名,否则其他的语句都得不到执行
一个con用完之后记得调用closecon