獲取db連接

public final class ConnectionFactory {
 
 /**
  * DBへの接続を試みる。
  * @return DB接続
  * @throws SQLException DBアクセス時に何らかのエラーが発生した場合。
  */
 public Connection getConnection() throws SQLException {
 
  try {
  
   final ResourceBundle resourceBundle = ResourceBundle.getBundle("Local");
  
   final String dbUrl = resourceBundle.getString("db.url");
   final String dbUserId = resourceBundle.getString("db.userid");
   final String dbPassword = resourceBundle.getString("db.password");
  
   Class.forName(resourceBundle.getString("JdbcDriver"));
   final Connection con = DriverManager.getConnection(dbUrl, dbUserId, dbPassword);
   con.setAutoCommit(false);
   con.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
  
   return con;
  
  }catch(ClassNotFoundException e){
   throw new SQLException(e.toString());
  }
 }
發佈了40 篇原創文章 · 獲贊 1 · 訪問量 8萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章