J2ee程序调用 JNDI 连接池
February 18, 2011 | tags JNDI | views
Comments 0
public static synchronized Connection getDCConn()
throws SQLException {
try {
DataSource ds=null;
Connection conn=null;
InitialContext ctx=new InitialContext();
ds=(DataSource)ctx.lookup("JNDI name");
conn=ds.getConnection();
return conn;
// Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");
// return DriverManager.getConnection("jdbc:db2:JLDSSDW", "admin", "admin");
}catch (Exception e) {
e.printStackTrace();
throw new SQLException(e.getMessage());
}
}