java - jdbc postgresql transaction error occurred -


public class jdbc {  static connection con; static statement stmt;  public static void main(string argv[]){  connect();  con.setautocommit(false);       // statement s=  conn.createstatement();         con.settransactionisolation(connection.transaction_serializable);          //set savepoint           system.out.println("savepoint1");         string sql = "insert flight values (1000, '22/7/2013', 'lgw', 'man', 10,40)";         stmt.executeupdate(sql);          savepoint savepoint1 = conn.setsavepoint("savepoint1");           string sql2 = "update flight set flightid = 500 flightid = 1000";         stmt.executeupdate(sql2);          con.rollback(savepoint1);           con.commit();         system.out.println("end"); }    static void connect() throws sqlexception, classnotfoundexception, datasourceexception {     try {         // load database driver driver          class.forname(datasource.getclassname());          // connect database given url given username ,         // password          connection con = drivermanager.getconnection(datasource.geturl(), datasource.getusername(), datasource.getpassword());          // create sql statement object         stmt = con.createstatement();     } catch (sqlexception se) {         con = null;         stmt = null;         throw (se);     }     }           } } 

hello, im trying understand how use savepoint. every time run program..it came out null pointer exception said error occur in con.setautocommit(false);

any suggestion appreciate....

most likely, have not initialized connection con variable. not showing part of code, cannot more.


Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -