java.sql.SQLException: 关闭的连接

/**
* 获得数据库连接
* @return
*/
public Connection getConnection(){
try {
//判断有问题
//if(conn != null)
//应该判断连接是否已关闭
if(conn != null && !conn.isClosed())
return conn;

String dbDriver = DBDRIVER;
String dbUrl = DBURL;
String dbUser = DBUSER;
String dbPwd = DBPWD;

Class.forName(dbDriver).newInstance();
conn = DriverManager.getConnection(dbUrl, dbUser, dbPwd);

if(conn == null)
throw new Exception("获取数据库连接失败!");
} catch (Exception e) {
e.printStackTrace();
}

return conn;
}

 

转载自:https://blog.csdn.net/hongweigg/article/details/7441648

posted @ 2018-12-24 09:11  根须  阅读(3634)  评论(0)    收藏  举报