0


I'm tring to access a DB2 data source on a remote machine, by a java web app deployed on a liberty websphere machine. In the moment the code execute the lookup ok the data source from the context the following error returns to me:

I FFDC1015I: An FFDC Incident has been created: "java.lang.ClassNotFoundException com.ibm.db2.jcc.DB2ConnectionPoolDataSource com.ibm.ws.injectionengine.processor.ResourceProcessor.loadTypeClass 1142" at ffdc_16.07.28_15.54.28.0.log"
W CWNEN0046W: The com.ibm.db2.jcc.DB2ConnectionPoolDataSource type specified on the resource-ref, resource-env-ref, or message-destination-ref with the jdbc/db2/primadb name in the db2-webapp.war module could not be loaded. Compatibility type checking will not be performed for this resource reference.

1)Have some help to access the data source?
2)Opened I opened the data source, I wuold like to open a connection and execute a prepared stateemnt on the the DB. Code here should be different from using the traditional javax.sql.Datasource?

the relevant part of my server.xml

 <dataSource jndiName="jdbc/db2/primadb" type="javax.sql.DataSource">
    <jdbcDriver javax.sql.DataSource="com.ibm.db2.jcc.DB2ConnectionPoolDataSource"
                libraryRef="db2Lib"/>
 <properties.db2.jcc driverType="4" serverName="172.17.0.3"
               portNumber="50000" databaseName="PRIMADB"
               user="db2inst1" password="*****"/>
</dataSource>

<library id="db2Lib">
    <fileset dir="lib" includes="*.jar"/>
</library>
 <application id="db2-webapp" name="Web App DB2">
    <classLoader commonLibraryRef="db2Lib"/>
</application>
Andy Guibert
  • 41,446
  • 8
  • 38
  • 61
grandeale83
  • 141
  • 2
  • 14
  • "java.lang.ClassNotFoundException com.ibm.db2.jcc.DB2ConnectionPoolDataSource" -- looks like the driver JAR is not in the classpath. – mustaccio Jul 28 '16 at 16:43
  • can you update your question with the server.xml configuration for your data source and also the resource ref? Also, are you directly using DB2 classes in your application (such as `com.ibm.db2.jcc.DB2ConnectionPoolDataSource`) or are you using the JDBC standard interfaces such as `javax.sql.DataSource`? – Andy Guibert Jul 28 '16 at 19:22

2 Answers2

0

As mustaccio mentioned, it's likely the jar is not on the classpath. For Liberty you should have an element like this in your server.xml:

<library id="DB2JCC4Lib">
    <fileset dir="C:/DB2/java" includes="db2jcc4.jar db2jcc_license_cisuz.jar"/>
</library>

Check to make sure com.ibm.db2.jcc.DB2ConnectionPoolDataSource exists at the location you have specified (and that you have read permission for it).

For further info: Configuring relational database connectivity in Liberty

mswatosh
  • 466
  • 2
  • 8
  • I edited the question with the relevant part of my server.xml. here is my library reference and the files have read permissions. – grandeale83 Jul 29 '16 at 08:48
0

Finally I solved this issue.

The issue was that my DB2 jars were not readable on my file system.

Here the relevant code parts of my configuration for future reference: Server.xml

<server description="Default server">
...
<dataSource jndiName="jdbc/db2/primadb" type="javax.sql.DataSource">
   <jdbcDriver libraryRef="db2Lib"/>
   <properties.db2.jcc  serverName="172.17.0.3"
                   portNumber="50000" databaseName="PRIMADB"
                   user="db2inst1" password="*****"/>
</dataSource>
<library id="db2Lib">
   <fileset dir="${shared.resource.dir}/db2" includes="*.jar"/>
</library>
...
</server>

My project deployment descriptor web.xml

<web-app>
   ...
   <resource-ref>
    <res-ref-name>jdbc/db2/primadb</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
   </resource-ref>
   ...
</web-app>

Finally the java code to access the database:

Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
DataSource ds = (DataSource) envCtx.lookup("jdbc/db2/primadb");
Connection conn = ds.getConnection();
try {
    Statement stmt = conn.createStatement();
    String first_name = request.getParameter("firstname");
    String last_name = request.getParameter("lastname");
    String country = request.getParameter("country");
    String sql = "INSERT INTO PRIMA_USER (id, firstname, lastname, country) VALUES (DEFAULT, '" + first_name
                        + "', '" + last_name + "' , '" + country + "')";
    stmt.execute(sql);
} finally {
    conn.close();
}

I would like to thank everybody to help in resolution.

Andy Guibert
  • 41,446
  • 8
  • 38
  • 61
grandeale83
  • 141
  • 2
  • 14
  • 1
    changing from `webProfile-6.0` to `7.0` only moves you from the `jdbc-4.0` to `4.1` feature. DB2 will work the same in either case. The only issue was that your libraries did not have read permissions. The feature changes in your server.xml are irrelevant. – Andy Guibert Jul 31 '16 at 21:28
  • @aguibert, It's true, I try also backing back to webProfile 6.0 and it works perfecly. Thanks – grandeale83 Aug 01 '16 at 08:31