1

I am trying to connect to a db2 database from my domino application without using the extension library.

I have created a managed bean that it only connects to the db2 and prints a message on the console.

I call the method of the managed bean from a button on an xpage.

The code in the bean is this:

Class.forName("com.ibm.db2.jcc.DB2Driver");
String url = "jdbc:db2://10.0.1.49:50000/AVIN";
String user = "db2admin";
String password = "ibmdb2";
con = DriverManager.getConnection(url, user, password);
System.out.println("Successful TEST JDBC Connection!!");

I have also configured my build path and added the db2jcc.jar library.

The problem is that i am getting

java.lang.ClassNotFoundException for com.ibm.db2.jcc.DB2Driver

Why is this happening?

mike_x_
  • 1,900
  • 3
  • 35
  • 69

1 Answers1

5

Is the DB2 JDBC driver available to your application? I suspect not.

You may need to package the driver in a plugin - within the NSF it will probably hit Java security issues and not work. More recent versions of the Extension Library (the Designer update site install) provide a menu option to Domino Designer to allow you to easily package up a JDBC driver as a plugin, which can then be deployed to your Update Site database.

I strongly recommend using the Extension Library. It will provide robust connection pooling amongst other things. Without it, you may well hit problems already considered and resolved by the experience of the Extension Library developers. If you do hit problems, you may struggle to find anyone with the experience to help you.

Paul Stephen Withers
  • 15,699
  • 1
  • 15
  • 33
  • is there any luck if i upload to /jvm/ext/lib path my db2jcc.jar? – mike_x_ Sep 16 '15 at 11:11
  • it did not work. i restarted the http task too but i get the same error. – mike_x_ Sep 16 '15 at 12:08
  • 2
    Restarting HTTP may not be enough. You're adding the jar to the server, not just the HTTP task (as would be the case with a plugin). As I say, it's not been the recommended approach since 8.5.3, so those with experience are limited. Maybe one of these links will give the answer http://stackoverflow.com/search?q=[xpages]+jvm%2Flib%2Fext – Paul Stephen Withers Sep 16 '15 at 12:45
  • 2
    Steve Zavocki and I presented at MWLUG 2015 about using DB2 with XPages and included a slide with an example of the java.policy file change you might need to make in addition to what it looks like you have already done – Dwain Wuerfel Sep 16 '15 at 14:05
  • I managed to connect. The problem was that i had to stop and then start the http task instead of typing the restart command. Restarting http task does not restart the jvm! So adding the connector to the jvm/lib/ext is a solution. The problem is that now i am getting NotSerializableException for a class in the connector... – mike_x_ Sep 17 '15 at 06:58
  • 1
    Ah, "tell http restart" doesn't fully restart HTTP. "restart task http" (which can be abbreviated to "res task http") does that. Make sure you've not got any Domino objects, because those will be non-serializable. – Paul Stephen Withers Sep 17 '15 at 09:00