public class DBConnUtil {
private static final String URL="jdbc:mysql://192.168.0.105:3306/imooc";
private static final String USER="zabbix";
private static final String PASSWORD="zabbix";
//声明一个静态变量
private static Connection conn = null;
//放到静态块中
static {
try {
//加载驱动
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection(URL,USER,PASSWORD);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
public static Connection getConn(){
return conn;
}
}我在每次使用完数据库后会关掉这个连接(按道理应该关闭吧)conn.close();然后第二次操作数据库就No operations allowed after connection closed.这个问题要怎么解决?总不能真的注销 conn.close(); 吧
添加回答
举报
0/150
提交
取消