Conn need to get their own, here I use when springjdbctemplate
Connection conn =NULL; PreparedStatement pstm=NULL; Try{conn=Jdbc.getdatasource (). getconnection (); } Catch(SQLException E1) {Log.error (E1.getmessage ()); return"Server Error! "; } fathermodule firsterrorfathermodule=NULL; String SQL=NULL; Try { for(Fathermodule fathermodule:fathermodules) {firsterrorfathermodule=Fathermodule; SQL= "Update Sfk_father_module t set T.sort =?" where t.id =?; "; Pstm=conn.preparestatement (SQL); Pstm.setint (1, Fathermodule.getsort ());//Note starting from 1Pstm.setlong (2, Fathermodule.getid ()); Pstm.executeupdate ();//Note that this is empty} conn.commit (); } Catch(SQLException e) {log.error (E.getmessage ()); Try{conn.rollback (); } Catch(SQLException E1) {Log.error ("Background Error"); } return"SortId =" +Firsterrorfathermodule.getsort (); } finally { if(pstm!=NULL) { Try{pstm.close (); } Catch(SQLException e) {log.error (E.getmessage ()); } } if(conn!=NULL) { Try{conn.close (); } Catch(SQLException e) {log.error (E.getmessage ()); } } } return NULL;
JDBC Implements transactions