尝试使用WEKA连接MySQL数据库时,我遇到了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)
答案 0 :(得分:5)
根据JavaDocs InstanceQuery默认为“jdbc.idbDriver”和“jdbc:idb = experiments.prp”。
您可以使用DatabaseUtils.properties
文件覆盖它们。尝试将DatabaseUtils.props
放入 user.home (/ home / talha /?)或当前目录(在Eclipse当前目录中是包含{{1}的项目文件夹文件夹 - 不知道它在IntelliJ Idea上的位置。)