java - Can't connect to sqlite from eclipse? -
hello guys have simple java , trying connect sqlite database eclipse doesn't work @ all.
here code:
import java.sql.connection; import java.sql.drivermanager; import java.sql.sqlexception; import java.sql.statement; public class databaseconnection { private string pathdb="c:\\sqlite\\test.db"; private connection connection=null; private statement statement=null; public databaseconnection(string path){ pathdb= path; } public void connect () { try { class.forname("org.sqlite.jdbc"); connection= drivermanager.getconnection("jdbc:sqlite:" + pathdb); statement= connection.createstatement(); system.out.println("connection " + pathdb + " "+ "successful"); } catch (classnotfoundexception notfoundexception) { notfoundexception.printstacktrace(); system.out.println("connection error!"); } catch (sqlexception sqlexception) { sqlexception.printstacktrace(); system.out.println("connection error!"); } string query="insert identity values(0,'issam','issam@mail.com')"; try { statement.executeupdate(query); } catch (sqlexception e) { e.printstacktrace(); } } public void close() { try { connection.close(); statement.close(); } catch (sqlexception e) { e.printstacktrace(); } } }
and main class:
public class main { public static void main(string[] args) { // todo auto-generated method stub databaseconnection connection= new databaseconnection("test.db"); connection.connect(); connection.close(); } }
so have sqlite database whenever run code gives me : connection "path" successful, no matter path put...
i think have done correctly, downloaded sqlite jdbc file , added it: enter image description here
i tried adding new row database table, gives me this:
connection test.db successful java.sql.sqlexception: no such table: identity @ org.sqlite.core.nativedb.throwex(nativedb.java:397) @ org.sqlite.core.nativedb._exec(native method) @ org.sqlite.jdbc3.jdbc3statement.executeupdate(jdbc3statement.java:116) @ com.issam.iamcore.databaseconnection.connect(databaseconnection.java:41) @ com.issam.iamcore.main.main(main.java:10) java.sql.sqlexception: [sqlite_error] sql error or missing database (connection closed) @ org.sqlite.core.db.newsqlexception(db.java:890) @ org.sqlite.core.corestatement.internalclose(corestatement.java:109) @ org.sqlite.jdbc3.jdbc3statement.close(jdbc3statement.java:35) @ com.issam.iamcore.databaseconnection.close(databaseconnection.java:63) @ com.issam.iamcore.main.main(main.java:11)
any appreeciated, !
you have connected database, did not create table identity
before executing insert query, says in stack trace:
connection test.db successful java.sql.sqlexception: no such table: identity
call before inserting row:
string createquery = "create table identity (id int primary key not null, name text, email text)"; statement.executeupdate(createquery);
Comments
Post a Comment