Results 1 to 10 of 10
  1. #1
    Join Date
    Jun 2011
    Posts
    8

    Red face Unanswered: 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.

  2. #2
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    The DB2 JDBC driver is not in the jar file and not in your classpath when you execute the jar file.

    Andy

  3. #3
    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.

  4. #4
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    Check your classpath or your development environment to find the file name. Yes, you can include it in your jar file.

    Andy

  5. #5
    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.

  6. #6
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    The driver you are using is not located in any of those files. You are using the JDBC driver, not the jcc driver.

    Andy

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

  8. #8
    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 !!**

  9. #9
    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.

  10. #10
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •