/**
* jndi 獲取連線
*
* @param jndiName
* @return
*/
public static Connection getconn(String jndiName) {
Connection conn = null;
try {
// weblogic 環境下使用
Hashtable ht = new Hashtable();
ht.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
ht.put(Context.PROVIDER_URL, "t3://localhost:7001");
ht.put(Context.SECURITY_PRINCIPAL, "weblogic");//使用者名稱
ht.put(Context.SECURITY_CREDENTIALS, "weblogic1");//密碼
Context ctx;
ctx = new InitialContext(ht);
DataSource source = (DataSource) ctx.lookup(jndiName);
Connection connection = source.getConnection();
if (connection != null) {
conn = connection;
}
} catch (NamingException e) {
log.error(e);
} catch (SQLException e) {
// logger.error(e);
return conn;
/**
* jndi 獲取連線
*
* @param jndiName
* @return
*/
public static Connection getconn(String jndiName) {
Connection conn = null;
try {
// weblogic 環境下使用
Hashtable ht = new Hashtable();
ht.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
ht.put(Context.PROVIDER_URL, "t3://localhost:7001");
ht.put(Context.SECURITY_PRINCIPAL, "weblogic");//使用者名稱
ht.put(Context.SECURITY_CREDENTIALS, "weblogic1");//密碼
Context ctx;
ctx = new InitialContext(ht);
DataSource source = (DataSource) ctx.lookup(jndiName);
Connection connection = source.getConnection();
if (connection != null) {
conn = connection;
}
} catch (NamingException e) {
log.error(e);
} catch (SQLException e) {
// logger.error(e);
log.error(e);
}
return conn;
}