It's all about the answers!

Ask a question

Unable to connect to DB2 database using server side plugin in rtc


Parveen Patel (77125) | asked Jun 12 '15, 4:24 a.m.
 Hi,
I have written a server side plugin (operation advisor)in which I am trying to connect to DB2 database and update values in database.
But I am not getting any connection to db2 database.
I have added db2jacc.jar and db2jcc_license_cu.jar to runtime in Manifest.mf file of plugin project.
Following is my code snippet for connecting to db2:
Object data = operation.getOperationData();
if (data instanceof ISaveParameter) {
// Get state of auditable item
ISaveParameter saveParameter = (ISaveParameter) data;
IAuditable auditable = saveParameter.getNewState();
// If everything is correct, the auditable is an WorkItem
if (auditable instanceof IWorkItem) {
IWorkItem newWorkItem = (IWorkItem) auditable;
try{
Class. forName ( "COM.ibm.db2os390.sqlj.jdbc.DB2SQLJDriver"  );
   Connection  connection = DriverManager.getConnection("jdbc:db2://localhost:50000/CCM","username","password");

  
String str = " select * from tablename";
       Statement stmt=connection.createStatement();  
 
ResultSet rs=stmt.executeQuery(str);  
 
while(rs.next())  {
String str1=rs.getString(1);
System.out.print(str1+" "+"\n");
}
//Update value of ID 
PreparedStatement stmt1=connection.prepareStatement("tablename set id=id + 1");  
 
 
int i=stmt1.executeUpdate();
//System.out.println(i+" records updated");
connection.close();   


Comments
Krzysztof Kaźmierczyk commented Jun 12 '15, 6:10 a.m.

Hi Parveen,
Do you have any error message?


Parveen Patel commented Jun 12 '15, 6:39 a.m.

 Hi Krzysztof Kazmierczyk,

How I print the exception message while connecting to DB2, which I am getting while running the advisor on WI editor?

One answer



permanent link
sam detweiler (12.5k6195201) | answered Jun 12 '15, 5:56 a.m.
edited Jun 12 '15, 5:56 a.m.
so that means probably one of these two statements failed

Class. forName ( "COM.ibm.db2os390.sqlj.jdbc.DB2SQLJDriver"  );
   Connection  connection = DriverManager.getConnection("jdbc:db2://localhost:50000/CCM","username","password");

did u debug it to find out why?

did the db2 driver jar get loaded to the plugin jar lib folder after build?  that is where my extra jar files are for one of my plugins


Comments
Parveen Patel commented Jun 12 '15, 6:47 a.m.

 Hi Sam,

 I have imported the required jar files in meta.inf folder in plugin project and after that I have added that to my plugins manifest.mf runtime.
These are the steps which  have followed to add DB2 jar files.
Please,guide me on this.


Thanks in advance

Your answer


Register or to post your answer.