I am trying to get a Java 9 module to connect to the Derby embedded database (insert mode). My module has a dependency java.sql, but I'm not sure where to put the Derby driver.
Here's mine module-info.java:
module mymodule {
requires java.sql;
}
Here is the code Main.javain the module that is not executing:
public static void main(String[] args) {
...
Connection conn;
try {
conn = DriverManager.getConnection("jdbc:derby:mysampledb");
Statement s = conn.createStatement();
s.executeUpdate("create table testtable (" +
"id VARCHAR(256), " +
"value VARCHAR(256)) ");
s.close();
}
catch (SQLException e) {
System.out.println("Error connecting " + e);
}
}
This compiles fine, but fails.
java -cp derbyjars --module-path out -m mymodule/foo.Main
Error connecting java.sql.SQLException: No suitable driver found for jdbc:derby:mysampledb
How to add database drivers? Is this using the -cp option? I put all the banks of the derby in a folder derbyjarsand I pass this to the parameter -cp. Is there any other way to get a module to see drivers?
source
share