0

I am trying to connect to a remote DB2 database located on a server. I have made the necessary DSN connection using ODBC and the test was successful. So in the below code i am using IMRM2 which is my DSN name, is that correct ?

But my main problem is i am getting the below error even after adding db2jcc.jar, db2jcc_license_cu.jar to my eclipse library. ?

Error:

java.lang.ClassNotFoundException: com.ibm.db2.jcc.DB2Driver
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at ConnectToDb2.makeConnection(CreateChart.java:19)
    at CreateChart.main(CreateChart.java:63)
Caused by: java.util.zip.ZipException: invalid LOC header (bad signature)
    at java.util.zip.ZipFile.read(Native Method)
    at java.util.zip.ZipFile.access$1400(Unknown Source)
    at java.util.zip.ZipFile$ZipFileInputStream.read(Unknown Source)
    at java.util.zip.ZipFile$ZipFileInflaterInputStream.fill(Unknown Source)
    at java.util.zip.InflaterInputStream.read(Unknown Source)
    at sun.misc.Resource.getBytes(Unknown Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$100(Unknown Source)
    ... 11 more

Java File.

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

class ConnectToDb2{

    String jdbcClassName="com.ibm.db2.jcc.DB2Driver";
    String url="jdbc:db2:IMRM2";
    String user="db2inst1";
    String password="DB2";
    Connection connection = null;


        public void makeConnection()
        {   

            try 
            {   
                Class.forName(jdbcClassName);
                connection = DriverManager.getConnection(url, user, password);
            } 

            catch (ClassNotFoundException e) 
            {
                e.printStackTrace();
            } 

            catch (SQLException e) 
            {
                e.printStackTrace();
            }


            finally
            {
                if(connection!=null)
                {
                    System.out.println("Connected successfully.");
                    try 
                    {
                        connection.close();
                    }

                    catch (SQLException e) 
                    {
                        e.printStackTrace();
                    }
                }
            }//End of finally 

        } // End of method makeConnection

}


public class CreateChart {


    public static void main(String[] args) {

        ConnectToDb2 obj_connectdb2 = new ConnectToDb2();

        obj_connectdb2.makeConnection();

    }

}
2
  • Can you share your projects eclipse build path ? Commented Apr 11, 2014 at 11:17
  • "java.util.zip.ZipException: invalid LOC header (bad signature)" - looks like your driver's jar file is corrupted Commented Apr 11, 2014 at 11:45

1 Answer 1

1

The root issue is indicated in this line:

Caused by: java.util.zip.ZipException: invalid LOC header (bad signature)

Your driver file is likely corrupt. If you use a zip program to open it, you may see errors indicated.

Solution: re-download your drivers.

Similar question, problem, and solution: tomcat7: Could not load JDBC driver class [com.mysql.jdbc.Driver]

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.