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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM