Weblogicの接続プール/データソースから接続を取得する方法
1384 ワード
//JDBC :,
public static Connection getConnection(){
Connection conn = null;
// , 。
String url = "jdbc:postgresql://127.0.0.1/getseus";
String userName = "ra";
String pwd = "ra";
try {
Class.forName("org.postgresql.Driver").newInstance();
conn = DriverManager.getConnection(url,userName,pwd);
} catch (Exception e){
e.printStackTrace();
}
return conn;
}
//JNDI
public static Connection getConnectionFromDS(){
Connection conn = null;
Context ctx = null;
try {
ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup("JNDIPG");
conn = ds.getConnection();
} catch (Exception e) {
e.printStackTrace();
}
return conn;
}
原文の出典:http://wallimn.iteye.com/blog/534259