2

我在尝试使用 WEKA 连接 MySQL DB 时遇到 JDBC 连接问题。

这是我的DatabaseUtils.properties文件:

jdbcDriver=com.mysql.jdbc.Driver
jdbcURL=jdbc:mysql://localhost:3306/mydb

我将 jdbc-mysql jar 添加到路径中:

/opt/SenchaSDKTools-2.0.0-beta3:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/talha/apache-maven-3.0.4/bin:/home/talha/mysql-connector-java-5.1.20.jar:/opt/SenchaSDKTools-2.0.0-beta3:/home/talha/apache-maven-3.0.4/bin:/usr/lib/jvm/jdk1.7.0_05/bin:/home/talha/apache-maven-3.0.4/bin

Java类【一个简单的测试类】

public class Test {

    public static void main(String[] args) throws Exception {

        InstanceQuery query = new InstanceQuery();
        query.setUsername("username");
        query.setPassword("password");
        String sql = "select * from user";
        query.setQuery(sql);
        // if your data is sparse, then you can say so too
        // query.setSparseData(true);
        Instances data = query.retrieveInstances();

    }

}

完整的堆栈跟踪:

Trying to add database driver (JDBC): RmiJdbc.RJDriver - Error, not in CLASSPATH?
Trying to add database driver (JDBC): jdbc.idbDriver - Error, not in CLASSPATH?
Trying to add database driver (JDBC): com.mckoi.JDBCDriver - Error, not in CLASSPATH?
Trying to add database driver (JDBC): org.hsqldb.jdbcDriver - Error, not in CLASSPATH?
Disconnected from the target VM, address: '127.0.0.1:33305', transport: 'socket'
Exception in thread "main" java.sql.SQLException: No suitable driver found for jdbc:idb=experiments.prp
    at java.sql.DriverManager.getConnection(DriverManager.java:604)
    at java.sql.DriverManager.getConnection(DriverManager.java:221)
    at weka.experiment.DatabaseUtils.connectToDatabase(DatabaseUtils.java:521)
    at weka.experiment.InstanceQuery.retrieveInstances(InstanceQuery.java:286)
    at weka.experiment.InstanceQuery.retrieveInstances(InstanceQuery.java:271)
    at com.tk.miner.Test.main(Test.java:22)
4

1 回答 1

5

根据 JavaDocs InstanceQuery默认为“jdbc.idbDriver”和“jdbc:idb=experiments.prp”。

DatabaseUtils.properties您可以使用文件覆盖它们。尝试放入DatabaseUtils.propsuser.home ( /home/talha/ ?) 或当前目录(在 Eclipse 中,当前目录是包含文件夹的项目文件src夹 - 不知道它在 IntelliJ Idea 上的位置)。

于 2012-09-18T06:38:49.303 回答