0
votes

I'm trying to use the Weka library to write my own software but it throws a JDBC driver exception.

My code (mostly copy-pasted from their tutorial):

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());

    }

}

I get this exception:

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)

I have added both the weka.jar and weka-src.jar files separately through Build Path - Add External JARs and I've also added the mysql-connector-java-5.1.34-bin.jar file through the same method.

If I write another test class to connect to the database it works (so it's definitely not an issue with the server):

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(); }
        }
    }
}
1

1 Answers

0
votes

Between switching the files, adding them to the build path etc, I had accidentally added a file without modifying the database parameter in the DatabaseUtils.prop file.