I am trying to connect to a SQLite database and since there is no officially supported driver; I decided to use the sqlite-jdbc driver and port the respective code into Mathematica. However, the DriverManager refuses to connect to the database, the error message is:
Java::excptn: A Java exception occurred: java.sql.SQLException:
No suitable driver found for jdbc:sqlite:C:/sqlite/test.db
at java.sql.DriverManager.getConnection(DriverManager.java:602)
at java.sql.DriverManager.getConnection(DriverManager.java:207).
The driver & the code that I am trying to port is at: https://bitbucket.org/xerial/sqlite-jdbc and the respective lines that I am having issue is:
....
Class.forName("org.sqlite.JDBC");
Connection connection = null;
try
{
// create a database connection
connection = DriverManager.getConnection("jdbc:sqlite:sample.db");
....
I noticed the code uses a Class.forName() and I used the JLinkClassLoader to load the same class. Here are my efforts so far:
< (*location of the driver jar*)
AddToClassPath["C:\\drivers\\sqlite"];
LoadJavaClass /@
{"java.sql.Connection", "java.sql.DriverManager", "java.sql.ResultSet",
"java.sql.Statement", "java.sql.SQLException","org.sqlite.JDBC"}
LoadJavaClass["com.wolfram.jlink.JLinkClassLoader"];
cls=Class`forName["org.sqlite.JDBC",True,JLinkClassLoader`getInstance[]];
(*Errors out with the message above*)
DriverManager`getConnection["jdbc:sqlite:C:/sqlite/test.db"]
I used DriverManager.getDrivers()
and it shows me that only the sun.jdbc.odbc driver has been loaded; so the error message is justified.
I am at this point not sure how to proceed /debug the issue and will greatly appreciate any assistance.
If you have any suggestions, I will be very grateful.
Comments
Post a Comment