0

I am writing a Java application which needs to insert some data to MySQL database through JDBC. Here's the related code:

public JDBCDecoder() {

    try {
        Class.forName("com.mysql.jdbc.Driver");
        System.out.println("Loaded MySQL JDBC driver");
    } catch (ClassNotFoundException e) {
        System.out.println("Exception attempting to load MySQL JDBC driver");
    }

    String url = "jdbc:mysql://localhost/db";

    Properties props = new Properties();
    props.put("user", "root");
    props.put("password", "root");

    try {
        conn = DriverManager.getConnection(url, props);
        conn.setAutoCommit(false);
    } catch (SQLException e) {
        Throwables.propagate(e);
    }
    ....

}

Here's the error stack trace that I got after trying to run the code:

java.lang.NoClassDefFoundError: Could not initialize class oracle.jdbc.OracleDriver
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:249)
    at java.sql.DriverManager.getCallerClass(DriverManager.java:477)
    at java.sql.DriverManager.getConnection(DriverManager.java:576)
    at java.sql.DriverManager.getConnection(DriverManager.java:154)
    at exportclient.JDBCExportClient$JDBCDecoder.<init>(JDBCExportClient.java:179)
    at exportclient.JDBCExportClient.constructExportDecoder(JDBCExportClient.java:604)
    at export.processors.GuestProcessor$1.run(GuestProcessor.java:113)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
    at utils.CoreUtils$1$1.run(CoreUtils.java:259)
    at java.lang.Thread.run(Thread.java:680)

which seems weird to me because: 1) I am not trying to connect to Oracle database; 2) actually I do have an ojdbc6.jar (which contains oracle.jdbc.OracleDriver) in my classpath. So I am completely clueless why this error would happen.

Any suggestion will be appreciated. Thanks in advance!

4

1 に答える 1

0

これが問題と関係があるかどうかを確認してください

于 2013-07-05T20:45:45.723 に答える