1

与 Websphere v7.0 建立数据库连接时运行独立 Java 客户端所需的所有 Jars

代码

Hashtable parms = new Hashtable();
parms.put(Context.INITIAL_CONTEXT_FACTORY, Database.DB_CONTEXT_FACTORY);
parms.put(Context.PROVIDER_URL, Database.DB_PROVIDER_URL);
logger.debug("Using context of database with parameter "+parms);
context = new InitialContext(parms);
dataSource = (DataSource) context.lookup(getName());
logger.debug("Using context of database with and the context is "+dataSource);
Connection conn = dataSource.getConnection();

错误

ERROR com.ibm.nzna.shared.util.LogSystem  - javax.naming.NoInitialContextException: Cannot instantiate class: com.ibm.websphere.naming.WsnInitialContextFactory [Root exception is java.lang.ClassNotFoundException: com.ibm.websphere.naming.WsnInitialContextFactory]
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:685)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:318)
at javax.naming.InitialContext.init(InitialContext.java:253)
at javax.naming.InitialContext.<init>(InitialContext.java:227)
at com.ibm.nzna.shared.db.Database.connect(Database.java:140)
at com.ibm.nzna.shared.db.DatabaseSystem.createConnection(DatabaseSystem.java:243)
at com.ibm.nzna.projects.qit.app.PCDInitializeThread.run(PCDInitializeThread.java:180)
at java.lang.Thread.run(Thread.java:780)
Caused by: java.lang.ClassNotFoundException: com.ibm.websphere.naming.WsnInitialContextFactory
at java.lang.Class.forName(Class.java:176)
at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:75)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:682)
    ... 7 more
4

1 回答 1

1

您似乎在类路径中缺少 WAS 7 客户端文件。从您的 WAS 安装中获取它们并将其添加到类路径中。您可能会在安装 ---> 运行时文件夹中找到这些 jar。

于 2013-01-30T22:16:20.817 回答