Reputation: 631
I'm writing a java program which needs to load a local SQLite database. Everything works as expected until I package it and try it on another computer. The database queries seem to be the only problem. Attempts return "No suitable driver found for jdbc:sqlite:C:\Data\Test.db". The error makes me think it's accessing the SQL classes but is not properly loading the drivers themselves.
String db_string = "C:\Data\Test.db";
try{
connection = DriverManager.getConnection("jdbc:sqlite:" + db_string);
Statement statement = connection.createStatement();
statement.setQueryTimeout(30); // 30 seconds
ResultSet rs = statement.executeQuery("select * from " + table);
while(rs.next()){
// Read the results
fileList.add(rs.getLong("modifieddate"));
}
} catch (SQLException e){
System.err.println(e.getMessage());
}
// Close the connection
finally {
try{
if(connection != null)
connection.close();
} catch (SQLException e){
System.err.println(e);
}
}
In IntelliJ I've built the Jar by creating a new Artifact and specifying the main class. The SQLite package I've used to read/write database information is extracted into the Jar by IntelliJ. When I open the Jar I can see my code and the SQLite code along with its JDBC drivers.
Manifest-Version: 1.0
Main-Class: com.myproject
The other computers I've tried it on are running Windows 8 and Windows 7. Both of them give the same errors.
What could possibly be wrong?
Upvotes: 0
Views: 1301
Reputation: 12766
You're not loading the driver class's static initializer by calling Class.forName(...)
and since you repacked the JAR, the SPI manifest needed to automatically detect the driver class probably isn't included.
Either manually invoke the driver or add the original SQLite driver JAR to your classpath instead of bundling it into a single JAR.
Upvotes: 1