Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

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

 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();   

0 votes

Comments

Hi Parveen,
Do you have any error message?

 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
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

1 vote

Comments

 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 log in to post your answer.

Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,938

Question asked: Jun 12 '15, 4:24 a.m.

Question was seen: 2,721 times

Last updated: Jun 12 '15, 6:47 a.m.

Confirmation Cancel Confirm