Friday 15 February 2013

java - Why connection throw timeoutException without commit -



java - Why connection throw timeoutException without commit -

i have dao class, has method below. phone call 1 within transaction manager. when ran without "conn.commit()" line - throws timeout exception, when ran 1 - ok. what's problem? know not necessary commit if not modify db?

@override public list<string> getlinks(int id) throws sqlexception { list<string> list = new arraylist<>(); connection conn = factory.newconnection(); statement statement = null; resultset rs = null; seek { string look = "select link users.links id=" + id + " order id_link desc"; statement = conn.createstatement(); rs = statement.executequery(expression); while (rs.next()) { list.add(rs.getstring("link")); } // !!!!!!!!!!!!! without next line method throw timeoutexception conn.commit(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! homecoming list; } grab (sqlexception e) { rollbackquietly(conn); e.printstacktrace(); } { closequaitly(rs); closequaitly(statement); closequaitly(conn); } homecoming null; }

seeing commit() phone call after line throwing exception, problem must come after repeated invocations of method (useful info include in question). leads me believe connection mill re-using connections, , handing out "stale" connections (connections have been sitting around long , no longer usable). if true, need create mill manage connections better. if reasonably built connection pool, has feature "test while idle" or "test on get" need enable.

java mysql commit connections transactionmanager

No comments:

Post a Comment