ClassNotFoundException when using JDBC driver for DB2

筅森魡賤 提交于 2020-03-06 04:45:25

问题


I'm trying to connect to a DB2 database using JDBC. Therefore I downloaded the DB2 driver db2jcc.jar and added the path to the classpath while compiling and running my application (I'm not using an IDE). The following is the source of my Test-Application:

import java.sql.*;

public class TestApp {
    public static void main(String[] args){
        try {
            Class.forName("com.ibm.db2.jcc.DB2Driver");
        }
        catch (Exception e) {
            System.out.println(e);
        }
    }
}

Does anybody know, where my problem is?


回答1:


Try compiling:

'javac -cp ".;(path)/db2jcc.jar;(path)/db2jcc_license_cu.jar" TestApp.java' 

Then running

'java -cp ".;(path)/db2jcc.jar;(path)/db2jcc_license_cu.jar" TestApp' 

You only need quotes if spaces in the file/path names also.



来源:https://stackoverflow.com/questions/17153477/classnotfoundexception-when-using-jdbc-driver-for-db2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!