は、私はそれを次のように解決:これは他の人が後で同じ問題/問題を持つことができます 希望を...
protected Connection getConnection() {
try {
if (connection == null || connection.isClosed()) {
if (dataSource == null) {
// impliziter Initial Context von WebLogic ApplicationServer Environment
java.util.Hashtable environment = new java.util.Hashtable();
environment.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
Context wlsic = new InitialContext(environment);
showJndiContext(wlsic, "", "");
// logischer JNDI Rootcontext der Serverkomponente, kann mehrfach verwendet werden
Context ctx = (Context) wlsic.lookup("java:comp/env");
showJndiContext(ctx, "", "");
// weiter mit Resourcenpfad
dataSource = (DataSource) ctx.lookup("MY_SQL_DS");
}
connection = dataSource.getConnection();
}
}
catch (NamingException ne) {
ne.printStackTrace();
log.error(ne);
}
catch (SQLException sqlEx) {
sqlEx.printStackTrace();
log.error(sqlEx.getMessage());
}
return connection;
}
public static void showJndiContext(Context ctx, String name, String space) {
if (null == name)
name = "";
if (null == space)
space = "";
try {
NamingEnumeration en = ctx.list(name);
while (en.hasMoreElements()) {
String delim = (null != name && 0 < name.length()) ? "/" : "";
NameClassPair nc = (NameClassPair) en.next();
System.out.println(space + name + delim + nc);
if (40 > space.length())
showJndiContext(ctx, nc.getName(), " " + space);
}
}
catch (javax.naming.NamingException ex) {
//System.out.println(ex);
}
}
出典
2009-03-10 17:51:23
yli