gpt4 book ai didi

java - Weka 在 Eclipse 中连接 MySQL

转载 作者:行者123 更新时间:2023-11-29 23:19:01 25 4
gpt4 key购买 nike

我正在尝试使用 Weka 库来编写自己的软件,但它引发了 JDBC 驱动程序异常。

我的代码(大部分是从他们的教程中复制粘贴的):

package test;

import weka.core.Instances;
import weka.experiment.InstanceQuery;

public class Test {

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

InstanceQuery query = new InstanceQuery();

query.setUsername("root");
query.setPassword("");
query.setQuery("select id_activite from ACTIVITES limit 1");

Instances data = query.retrieveInstances();
System.out.println(data.toString());

}

}

我得到这个异常:

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?
Exception in thread "main" java.sql.SQLException: No suitable driver found for jdbc:idb=experiments.prp
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at weka.experiment.DatabaseUtils.connectToDatabase(DatabaseUtils.java:523)
at weka.experiment.InstanceQuery.retrieveInstances(InstanceQuery.java:286)
at weka.experiment.InstanceQuery.retrieveInstances(InstanceQuery.java:271)
at seniorhome.Test.main(Test.java:17)

我通过“构建路径 - 添加外部 JAR”分别添加了 weka.jar 和 weka-src.jar 文件,并且还通过相同的方式添加了 mysql-connector-java-5.1.34-bin.jar 文件方法。

如果我编写另一个测试类来连接到数据库,它就可以工作(所以这绝对不是服务器的问题):

public class test {
public static void main(String[] args) {
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
// new com.mysql.jdbc.Driver();
Class.forName("com.mysql.jdbc.Driver").newInstance();
// conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/testdatabase?user=testuser&password=testpassword");
String connectionUrl = "jdbc:mysql://localhost:3306/b3l";
String connectionUser = "root";
String connectionPassword = "";
conn = DriverManager.getConnection(connectionUrl, connectionUser, connectionPassword);
stmt = conn.createStatement();
rs = stmt.executeQuery("SELECT id_activite FROM activites");
while (rs.next()) {
String id = rs.getString("id_activite");
System.out.println("ID: " + id);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try { if (rs != null) rs.close(); } catch (SQLException e) { e.printStackTrace(); }
try { if (stmt != null) stmt.close(); } catch (SQLException e) { e.printStackTrace(); }
try { if (conn != null) conn.close(); } catch (SQLException e) { e.printStackTrace(); }
}
}
}

最佳答案

在切换文件、将它们添加到构建路径等过程中,我不小心添加了一个文件,而没有修改 DatabaseUtils.prop 文件中的数据库参数。

关于java - Weka 在 Eclipse 中连接 MySQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27503612/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com