将JDBC驱动程序用于DB2时发生ClassNotFoundException [英] ClassNotFoundException when using JDBC driver for DB2

查看:197
本文介绍了将JDBC驱动程序用于DB2时发生ClassNotFoundException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用JDBC连接到DB2数据库。因此,我在编译和运行应用程序时下载了DB2驱动程序 db2jcc.jar 并将路径添加到类路径中(我没有使用IDE)。
以下是我的测试应用程序的来源:

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?

推荐答案

尝试编译:

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

然后运行

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

如果文件中有空格,则只需要使用引号/ path名称。

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

这篇关于将JDBC驱动程序用于DB2时发生ClassNotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆