Thursday, 15 April 2010

java - JDBC for SQLite in Netbeans: No suitable driver found -



java - JDBC for SQLite in Netbeans: No suitable driver found -

i need load info sqlite file java programme develop in netbeans. file loaded via swing menu item. i'm using sqlitejdbc driver.

here code blocks assume important:

// header stuff bundle aufgabe_9; import java.sql.*; //... // menu item opening file private void mitemopenfileactionperformed(java.awt.event.actionevent evt) { /** * handles dialogue selecting , loading file. */ jfilechooser filechoose = new jfilechooser(); filechoose.showopendialog(this); //'this' calls current object //load sql file seek { string filepath = filechoose.getselectedfile().tostring(); connection conn = drivermanager.getconnection("jdbc:sqlite:" + filepath); //close connection if (conn != null) conn.close(); } grab (sqlexception e){system.err.println("database problem: " + e);} } } //...

when running programme , loading file via menu, next error:

java.sql.sqlexception: no suitable driver found jdbc:sqlite:/home/levent /temp/a9aprobeflaeche.db

after reading respective stackexchange posts, understand problem can caused (1) malformed file url or (2) driver not beingness loaded. here's farther information:

i added sqlitejdbc-3.7.2.jar library classpath via tools --> libraries project libraries via window --> projects. i checked classpath using this function. contains path jdbc jar-file expected. i can connect database via services menu without problems, can assume url correct, sqlite running on system. some os information: i'm running netbeans 8.0 on 64 bit arch linux 3.12.9-2.

can tell me i'm missing here? help appreciated!

problem solved here code works me:

//... private void mitemopenfileactionperformed(java.awt.event.actionevent evt) { /** * handles dialogue selecting , loading file. */ jfilechooser filechoose = new jfilechooser(); filechoose.showopendialog(this); //load sql file seek { //get file path string filepath = filechoose.getselectedfile().tostring(); //open connection class.forname("org.sqlite.jdbc"); connection conn = drivermanager.getconnection("jdbc:sqlite:" + filepath); //do stuff... //close connection conn.close(); } //"multicatch": grab (sqlexception | classnotfoundexception e) { system.err.println("database problem: " + e); } //...

you need load driver class registers drivermanager using next code: class.forname("org.sqlite.jdbc");

note: needs called 1 time in application.

this standard procedure before java included serviceloader api, drivermanager uses api register drivers finds in classpath, drivers need declare file named java.sql.driver containing name of driver class in directory meta-inf\services of jar.

java sqlite netbeans jdbc sqlexception

No comments:

Post a Comment