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