I have no clue (too stupid), why my app doesn't find the jdbc class at runtime:
Exception in thread "main" java.lang.ClassNotFoundException: org.sqlite.JDBC
Do you have any hint ? Complete Simplified usecase in this repo : https://bitbucket.org/solvapps/jdbcapp
I have added a module called "maintain" to my Androidstudio project for maintaining stuff, which should not be included in the app. (I have done this already with another app).
My maintain gradle :
apply plugin: 'java'
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
sourceCompatibility = "1.8"
targetCompatibility = "1.8"
repositories {
mavenCentral()
}
dependencies {
compile 'org.xerial:sqlite-jdbc:3.16.1'
compile 'commons-net:commons-net:3.3'
compile 'org.zeroturnaround:zt-zip:1.11'
compile 'org.zeroturnaround:zt-zip:1.11'
compile 'org.apache.commons:commons-lang3:3.5'
}
After sync I see the jar in External Libraries.
My code, which is not red :
public static void connect(String language, boolean readonly) throws SQLException, ClassNotFoundException, IOException {
// Hole DBPath
String dbpath = Constants.getDbName(language);
Class.forName("org.sqlite.JDBC");
SQLiteConfig config = new SQLiteConfig();
if (readonly){
config.setReadOnly(true);
}else{
config.setReadOnly(false);
}
connection = DriverManager.getConnection("jdbc:sqlite:" + dbpath,config.toProperties());
}
Error:
Exception in thread "main" java.lang.ClassNotFoundException: org.sqlite.JDBC
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at solveraapps.maintain.DbService.connect(DbService.java:24)