java - What is the accurate syntax for SQLite JDBC Connections? -


this may repeated question but, not. have tried looking answer on 48 hours no result.

firstly, closing preparedstatment & resultset necessary in sqlite jdbc connection? because unable so.

try {         class.forname(database.getjdbc_driver());         cnn = drivermanager.getconnection(database.getdb_url());         p = cnn.preparestatement(query);         rs = p.executequery();         p.close();         cnn.close();     } catch (sqlexception e) {         e.printstacktrace();     } catch (classnotfoundexception e) {         e.printstacktrace();     } {         try {             system.out.println(p.isclosed());             if (cnn != null) cnn.close();             system.out.println(p.isclosed());         } catch (sqlexception e) {             e.printstacktrace();         }     } 

as can see, closed preparedstatement inside try block. however, when i'm checking state of same outside try block, result false. (which means isn't closed).

besides, if have below code in block, throws error stating connection closed. super confused on do. should leave is. wouldn't code have leakage?

} {     try {         if (p != null) p.close(); *// errors out here...*         if (cnn != null) cnn.close();     } catch (sqlexception e) {         e.printstacktrace();     } } 

below stack trace -

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)     @ tg.cat.dropdown.getdata(dropdown.java:28)     @ tg.loginscreen.loginscreenlayout.<init>(loginscreenlayout.java:22)     @ tg.cat.catmain.getscene(catmain.java:27)     @ tg.cat.catmain.start(catmain.java:18)     @ com.sun.javafx.application.launcherimpl.lambda$launchapplication1$159(unknown source)     @ com.sun.javafx.application.launcherimpl$$lambda$53/855499929.run(unknown source)     @ com.sun.javafx.application.platformimpl.lambda$runandwait$172(unknown source)     @ com.sun.javafx.application.platformimpl$$lambda$45/186276003.run(unknown source)     @ com.sun.javafx.application.platformimpl.lambda$null$170(unknown source)     @ com.sun.javafx.application.platformimpl$$lambda$48/1635925971.run(unknown source)     @ java.security.accesscontroller.doprivileged(native method)     @ com.sun.javafx.application.platformimpl.lambda$runlater$171(unknown source)     @ com.sun.javafx.application.platformimpl$$lambda$47/237061348.run(unknown source)     @ com.sun.glass.ui.invokelaterdispatcher$future.run(unknown source)     @ com.sun.glass.ui.win.winapplication._runloop(native method)     @ com.sun.glass.ui.win.winapplication.lambda$null$145(unknown source)     @ com.sun.glass.ui.win.winapplication$$lambda$36/2117255219.run(unknown source)     @ java.lang.thread.run(unknown source) 

the finally block executed regardless of whether exception thrown or not. don't need use close connection again, use place close connection. second, note closing connection not reset variable null:

try {     class.forname(database.getjdbc_driver());     cnn = drivermanager.getconnection(database.getdb_url());     p = cnn.preparestatement(query);     rs = p.executequery(); } catch (sqlexception e) {     e.printstacktrace(); } catch (classnotfoundexception e) {     e.printstacktrace(); } {     try {         if (rs != null) {              rs.close();         }         if (p != null) {              p.close();         }         if (cnn != null) {              cnn.close();         }     } catch (sqlexception e) {         system.err.println("can't close object, not can do");     } } 

Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -