Java SQL Server Application Stuck On statement.executeUpdate() -
i have rather annoying issue. in piece of code below, trying insert new row "revisiondispersion" table in database. however, whenever call stmt.executeupdate() program freezes , there ends being no transaction database. no matter how long wait; database won't updated. below code of interest:
private static final string insert_dispersion = "insert revisiondispersion(" + assignments.id + ", " + persons.email + ", " + handins.id + ")" + " values(?, ?, ?)"; public static void disperse(datasource source, assignment assignment) throws exception { list<string> handins = assignment.gethandins(); //used decide checks assignment int maxrng = math.max(1, handins.size() / assignment.getpeercount()); int rng = new random().nextint(maxrng); preparedstatement stmt = null; connection con = null; try{ //get connection, set transaction_serializable , set autocommit false con = source.getconnection(); configureconnection(con); //prepare statement insert new dispersion stmt = con.preparestatement(insert_dispersion); stmt.setstring(1, assignment.getid()); //iterate on hand-ins , decide peer peer receives feedback for(int = 0; < handins.size(); i++) { handin handin = new handin(source.getconnection(), handins.get(i)); string student = handin.getemail(); stmt.setstring(2, student); for(int j = 1; j <= assignment.getpeercount(); j++) { handin otherhandin = new handin(source.getconnection(), handins.get(j * rng)); stmt.setstring(3, otherhandin.getid()); stmt.executeupdate(); } } con.commit(); }catch(exception e){ throw e; }finally{ closequietly(con, stmt); } } //this method in dbao class, put here folks. protected static void configureconnection(connection connection) throws sqlexception { connection.setautocommit(false); connection.settransactionisolation(connection.transaction_serializable); }
this problem occurs in no other places in application. whenever run sql statement in sql server management studio, identical parameters, not stuck , inserts new rows fine. after deleting rows , trying same in application, gets stuck.
can point me in right direction of going wrong? i've been trying 3 hours straight now...
stuff tried
-use stmt.addbatch() rather executeupdate() (did not make difference. stuck @ executebatch())
-check if connections being closed properly; are.
-check if other statements/resultsets still open use revisiondispersion table (there none still open. if there were, should not make difference think?)
-completely delete database , set up
i solved issue...
in different piece of code had following:
private static final string get_not_dispersed = "select * assignments " + assignments.close_date + "<=? , " + assignments.peer_start_date + ">=? , " + assignments.id + " not in(select " + assignments.id + " revisiondispersion)"; private void makemaildispersion() throws exception { datetime currentdate = datetime.getcurrentdatetime(); preparedstatement assignmentsstmt = null; resultset assignments = null; connection con = null; try{ con = source.getconnection(); configureconnection(con); assignmentsstmt = con.preparestatement(get_not_dispersed); assignmentsstmt.setstring(1, currentdate.tostring()); assignmentsstmt.setstring(2, currentdate.tostring()); assignments = assignmentsstmt.executequery(); arraylist<assignment> requiresdispersion = new arraylist<>(); assignments.close(); assignmentsstmt.close(); while(assignments.next()) { assignment assignment = new assignment(source.getconnection(), assignments.getstring(assignments.id)); assignmentdisperser.disperse(source, assignment); } }catch(exception e){ throw e; }finally{ closequietly(con, assignmentsstmt, assignments); } }
in piece of code, closed variables 'assignments' , 'assignmentsstmt'. thought sufficient unlock table after having used get_not_dispersed query. apparently not: table still locked.
what had in order fix it: aside calling assignments.close() , assignmentsstmt.close() had call con.close(). unlocked table , allowed code run properly.
Comments
Post a Comment