我在尝试使用 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)