Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

DataSource problem when running app from launchClient

24 views
Skip to first unread message
Message has been deleted

crash.test.dummy

unread,
Oct 1, 2007, 5:12:24 PM10/1/07
to
i have created a sample app that connects to a database. the
connection details (jdbc type 4) are defined in WAS (v6.0.2.21), hence
i need to run the sample app through launchClient.

o From the admin console, I defined the JNDI: jdbc/dbPool to use the
JAR files:
Classpath: /opt/udb/java/db2jcc.jar
/opt/udb/java/db2jcc_license_cu.jar
/opt/udb/java/db2jcc_license_cisuz.jar
Implementation classname:
com.ibm.db2.jcc.DB2ConnectionPoolDataSource
Data Source Helper Classname:
com.ibm.websphere.rsadapter.DB2UniversalDataStoreHelper

i tested the JNDI data source configuration though the "Test
Connection" button on the admin console and it connects successfully.

however, running the app from a command line fails. Here are the
details.

//code: MyConnection.java
...
public class MyConnection {
public static void main(String[] args) throws Exception {
System.out.println("Starting MyConnection...");
MyConnection myConn = new MyConnection();
Connection conn = myConn.openConnection();
System.out.println("Connection is now open.");
myConn.queryTable(conn);
if (conn != null) {
conn.close();
System.out.println("Connection has been
closed.");
}
System.out.println("MyConnection completed.");
}
private Connection openConnection() throws NamingException,
SQLException {
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.ibm.websphere.naming.WsnInitialContextFactory");
Context ctx = (Context) new
InitialContext(env).lookup("java:comp/env");
DataSource ds = (DataSource)ctx.lookup("jdbc/dbPool");
return ds.getConnection();
}
private void queryTable(Connection conn) {
PreparedStatement stmt = null;
ResultSet rs = null;
StringBuffer sql = new StringBuffer();
sql.append("SELECT COLUMN1 ");
sql.append(" FROM TABLE1 ");
try {
stmt = conn.prepareStatement(sql.toString());
rs = stmt.executeQuery();
while (rs.next()) {
System.out.println("COLUMN1 = " +
rs.getString(1));
}

} catch (SQLException e) {
e.printStackTrace();
} finally {
if (rs != null) {
rs.close();
}
if (stmt != null) {
stmt.close();
}
if (conn != null) {
conn.close();
}
}
}
}

// application client bindings:
...
<application-client id="Application-client_ID">
<display-name>TestConnection</display-name>
<resource-env-ref id="ResourceEnvRef_1191252374147">
<description>reference to JNDI jdbc/dbPool</
description>
<resource-env-ref-name>jdbc/dbPool</resource-env-ref-
name>
<resource-env-ref-type>javax.sql.DataSource</resource-
env-ref-type>
</resource-env-ref>
</application-client>

// script for running the app:
WAS_APPSRVR_BIN=/opt/was6/appserver/bin
BATCH_EAR=/sample/batch/ear
BOOTSTRAP_HOST=server1.sample.com
BOOTSTRAP_PORT=19010
JDBC_DRIVERS=/opt/udb/java/db2jcc.jar\;/opt/udb/java/
db2jcc_license_cisuz.jar\;/opt/udb/java/db2jcc_license_cu.jar
TRACE_FILE=/sample/batch/log/trace1.log

${WAS_APPSRVR_BIN}/launchClient.sh ${BATCH_EAR}/TestConnBatch.ear
CCBootstrapHost=${BOOTSTRAP_HOST} \
-CCBootstrapPort=${BOOTSTRAP_PORT} -CCclasspath=${JDBC_DRIVERS} \
-CCverbose=true -CCdumpJavaNameSpace=true \
-
CCDjava.naming.factory.initial=com.ibm.websphere.naming.WsnInitialContextFactory
\
-CCtrace=true -CCtracefile=${TRACE_FILE} MyConnection

// from the logs:
Starting MyConnection...
WSCL0100E: Exception received:
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
25)
at java.lang.reflect.Method.invoke(Method.java:324)
at
com.ibm.websphere.client.applicationclient.launchClient.createContainerAndLaunchApp(launchClient.java:
638)
at
com.ibm.websphere.client.applicationclient.launchClient.main(launchClient.java:
425)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
25)
at java.lang.reflect.Method.invoke(Method.java:324)
at com.ibm.ws.bootstrap.WSLauncher.main(WSLauncher.java:189)
Caused by:
com.ibm.websphere.naming.CannotInstantiateObjectException:Exception
occurred while the JNDI NamingManager was processing a
javax.naming.Reference object. [Root exception is
com.ibm.websphere.naming.CannotInstantiateObjectException: Exception
occurred while the JNDI NamingManager was processing a
javax.naming.Reference object. [Root exception is
javax.naming.NamingException: ClassNotFoundException:
com.ibm.db2.jcc.DB2ConnectionPoolDataSource [Root exception is
java.lang.ClassNotFoundException:
com.ibm.db2.jcc.DB2ConnectionPoolDataSource]]]
at
com.ibm.ws.naming.util.Helpers.processSerializedObjectForLookupExt(Helpers.java:
931)
at
com.ibm.ws.naming.urlbase.UrlContextHelper.processBoundObjectForLookup(UrlContextHelper.java:
152)
at
com.ibm.ws.naming.urlbase.UrlContextImpl.processBoundObjectForLookup(UrlContextImpl.java:
1777)
at
com.ibm.ws.naming.urlbase.UrlContextImpl.lookup(UrlContextImpl.java:
1278)
at
com.ibm.ws.naming.urlbase.UrlContextImpl.lookup(UrlContextImpl.java:
1307)
at MyConnection.openConnection(MyConnection.java:52)
at MyConnection.main(MyConnection.java:35)


>From the log, it says that the com.ibm.db2.jcc.DB2ConnectionPoolData
file is not found.
In the script, I have added the -CCclasspath to define the jar file
(db2jcc.jar, among others), but still can't find it.

Any help is appreciated.

crash.test.dummy

unread,
Oct 10, 2007, 11:10:11 AM10/10/07
to
i found a solution on this one.

i added the jdbc drivers (db2jcc.jar, db2jcc_license_cisuz.jar,
db2jcc_license_cu.jar) in my TestConnBatch.ear and it works.

IHMO, this solution is awkward as it defeats the purpose of using JNDI
and having the jdbc drivers managed outside my application.

Dexthor

unread,
Oct 11, 2007, 9:39:23 AM10/11/07
to


You sound like DNS Server - since it responds with an Address for a
Name, should also run the Service !

JNDI is just a directory service. If you want full fledged service to
handle all DB interactions then you better write a WebSerivce(SOAP
over HTTP) or an EJB (RMI). JNDI will simply provide you information
on the configuration of the NAME that you are requesting. Your runtime
must be capable of instantiating that configuration, which means you
must have access to DB drivers & API to communicate with whatever
backend it has.


-GM.

crash.test.dummy

unread,
Oct 17, 2007, 12:30:27 PM10/17/07
to
thanks for your reply.

one odd thing is that i specified a -CCclasspath parameter when
running the launchClient. this should take care of the JAR files that
are not included in the EAR file.

-CCclasspath=/opt/udb/java/db2jcc.jar\;/opt/udb/java/
db2jcc_license_cisuz.jar\;/opt/udb/java/db2jcc_license_cu.jar

i did a system.out on the java.class.path property and it only shows
up the classloader's JAR files.

System.out.println("classpath = " +
System.getProperty("java.class.path"));

classpath = /opt/was6/appserver/properties:/opt/was6/appsrvinstall/
properties:/opt/was6/appsrvinstall/lib/bootstrap.jar:/opt/was6/
appsrvinstall/lib/j2ee.jar:/opt/was6/appsrvinstall/lib/lmproxy.jar:/
opt/was6/appsrvinstall/lib/urlprotocols.jar

(i noticed that the output uses colon as the delimiter for multiple
entries. i tried to use the same on -CCclasspath, but the classpath
didn't change).

any ideas on how to add new JAR files to the launchClient's classpath?


Message has been deleted
0 new messages