简体   繁体   中英

java.lang.ClassNotFoundException: com/ibm/db2/jcc/DB2Driver - DB2

Using my below-given java code, I am trying to connect to DB2 database. Till yesterday, I was able to connect to DB2 database but suddenly today, I started to face below give the exception -

java.lang.ClassNotFoundException: com/ibm/db2/jcc/DB2Driver;
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at com.rolta.ntpc.Util.JdbcDB2Connection.getConnection(JdbcDB2Connection.java:37)
    at com.rolta.ntpc.Util.ReadDataFromXLSFile.truncateTable(ReadDataFromXLSFile.java:155)
    at com.rolta.ntpc.test.TestNTPCDataTransfer.storeData(TestNTPCDataTransfer.java:93)
    at com.rolta.ntpc.test.TestNTPCDataTransfer.transferDataToDB2(TestNTPCDataTransfer.java:40)
    at com.rolta.ntpc.test.TestNTPCDataTransfer.main(TestNTPCDataTransfer.java:32)

Property File having below-given information -

DB2Driver=com.ibm.db2.jcc.DB2Driver;
DB2ConnectionURL="jdbc:db2://100.38.0.172:50000/DREAMS";
DB2UserName="dbr";
DB2Password="Welcome@123";

My DB2 database version is 11.1 and my java code to connect to DB2 is -

public static Connection getConnection() {

        Properties prop = LoadProperties.getProperties();
        logger.info("Properties From Property File : ");
        logger.info("DB2Driver : "+prop.getProperty("DB2Driver"));
        logger.info("DB2ConnectionURL : "+prop.getProperty("DB2ConnectionURL"));
        logger.info("DB2UserName : "+prop.getProperty("DB2UserName"));
        logger.info("DB2Password : "+prop.getProperty("DB2Password"));

        Connection connection = null;
        try {

            Class.forName(prop.getProperty("DB2Driver"));
            connection = DriverManager.getConnection(prop.getProperty("DB2ConnectionURL"), 
                                                     prop.getProperty("DB2UserName"), 
                                                     prop.getProperty("DB2Password"));

            if(connection != null) {
                System.out.println("Connected successfully.");
            } else {
                System.out.println("Colud not Connect successfully.");
            }

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

        return connection;
    }

I have below-given jar files in my project.

在此处输入图片说明

Can anyone please help me in knowing why this exception is coming and what is the solution?

Per comment thread, it was a change to the properties file .

The correct class name should be com.ibm.db2.jcc.DB2Driver

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM