1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
public static void main (String [] args) {
Hashtable ht = new Hashtable();
ht.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
ht.put(Context.SECURITY_AUTHENTICATION, "ssl");
ht.put(Context.SECURITY_PRINCIPAL, "xxx");
ht.put(Context.SECURITY_CREDENTIALS, yyy");
ht.put(Context.PROVIDER_URL, "t3://serverX:7001");
try {
Context initCtx = new InitialContext(ht);
DataSource ds = (DataSource) initCtx.lookup("jdbc/bbb");
try {
Connection con = ds.getConnection();
if (con != null) {
System.out.println("connection is not null");
}
} catch (Exception ex) {
ex.printStackTrace();
}
} catch (NamingException e) {
e.printStackTrace();
}
} |
Partager