If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > DB2 problem with jar file

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-05-11, 08:30
souravmondal10 souravmondal10 is offline
Registered User
 
Join Date: Jun 2011
Posts: 8
Red face DB2 problem with jar file

i have developed an application using java and db2.i have made the class files.everything is working fine.now i have made a jar files from the class files.i am executing the jar file using the command "java -jar pis.jar",where pis is the name of jar file.when it is showing an exception "COM.ibm.db2.jdbc.app.DB2Driver" at the time i am executing the jar file.
i have use that line in the program in this way---



try{

Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");
con=DriverManager.getConnection("jdbc:db2AMPLE", "db2admin","db2admin");

}
catch(Exception e4){
System.out.println(e4.getMessage());}
}




the form is coming and all non-database related forms are working but all the forms related to db2 are not working.when i am using the class files that time the database related all things are working.
please help.
Reply With Quote
  #2 (permalink)  
Old 07-05-11, 10:17
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
The DB2 JDBC driver is not in the jar file and not in your classpath when you execute the jar file.

Andy
Reply With Quote
  #3 (permalink)  
Old 07-05-11, 13:30
souravmondal10 souravmondal10 is offline
Registered User
 
Join Date: Jun 2011
Posts: 8
ok sir.now what i have to do?
i know how to set the classpath.but where is is that driver file is located?what is the name of that file?please reply.do i need to include that drive file also to jar while zipping all the files to jar file?
thank u for the reply.
Reply With Quote
  #4 (permalink)  
Old 07-05-11, 13:34
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
Check your classpath or your development environment to find the file name. Yes, you can include it in your jar file.

Andy
Reply With Quote
  #5 (permalink)  
Old 07-05-11, 13:47
souravmondal10 souravmondal10 is offline
Registered User
 
Join Date: Jun 2011
Posts: 8
i included 3 files to classpath and to my jar.they are db2cc.jar,common.jar and db2jcc_license_cu.jar.
still not working.
Reply With Quote
  #6 (permalink)  
Old 07-05-11, 13:54
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
The driver you are using is not located in any of those files. You are using the JDBC driver, not the jcc driver.

Andy
Reply With Quote
  #7 (permalink)  
Old 07-05-11, 21:54
souravmondal10 souravmondal10 is offline
Registered User
 
Join Date: Jun 2011
Posts: 8
now i am using this:--
Class.forName("com.ibm.db2.jcc.DB2Driver");

but not working.showing exception com.ibm.db2.jcc.DB2Driver
what to do?please help.
Reply With Quote
  #8 (permalink)  
Old 07-05-11, 23:49
singhipst singhipst is offline
Registered User
 
Join Date: Jul 2006
Location: Bangalore
Posts: 57
looks like you have problem in "con=DriverManager.getConnection("jdbc:db2SAMP LE", "db2admin","db2admin");"

I have used below code many time and it worked with those 3 jar file (DB2 JDBC Driver) you used. Driver files you can get <DB2 Home Directory>\IBM\SQLLIB\java

Code:
	private static void runDb2Query(String queryStr){
		Connection conn	= null;
		String url="jdbc:db2://localhost:50003/SAMPLE";
                String queryStr="select current date from sysibm.sysdummy1";
		try {
			Class.forName ("com.ibm.db2.jcc.DB2Driver");
			conn = DriverManager.getConnection(url, "db2admin", "password");

	        Statement stmt = conn.createStatement();
	        ResultSet rset = stmt.executeQuery(queryStr);	        
	        stmt.close();
	        conn.close();
		}catch (SQLException se) {
			se.printStackTrace();
		}catch (Exception e) {			
			e.printStackTrace();
		}
	}
__________________
Ritesh Kumar Singh
IBM Certified DB2 DBA for LUW
**Knowledge Is Theft If Not Shared !!**
Reply With Quote
  #9 (permalink)  
Old 07-06-11, 04:00
souravmondal10 souravmondal10 is offline
Registered User
 
Join Date: Jun 2011
Posts: 8
sorry sir.i think you didn't get my point.the type2 and type 4 driver i have used.it is working fine.when i am using the class file using command "java classname" it is working fine.no problem for me.but when i am combining all the class files to a executable jar that time it is not working.but in jar file all non-db2 related forms are working.
Reply With Quote
  #10 (permalink)  
Old 07-06-11, 09:49
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
You consistently do not give us the exact exception you are getting. We can only assume that it is the most common one (class not found). If this is the case then the JVM cannot find the db2 driver in the classpath--which is what we have been pointing out all along. Now if the exception is something else, then you are keeping us in the dark and we will never find the correct solution.

Andy
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On