SpObserver.putSp( "sessionFactory1" ); |
02 | SimpleDateFormat fomat = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" ); |
03 | Session s= null ; |
04 | s=daoSupport.getSessionFactory().openSession(); |
05 | Connection con=s.connection(); |
06 | Statement stmt = null ; |
07 | try { |
08 | stmt=con.createStatement(); |
09 | con.setAutoCommit( false ); |
10 | Iterator it=list.iterator(); |
11 | int iCount = 1 ; |
12 | long start = System.currentTimeMillis(); |
13 | while (it.hasNext()){ |
14 | TResultWaterZId t = (TResultWaterZId)it.next(); |
15 | StringBuffer sb = new StringBuffer(); |
16 | sb.append( "insert into T_result_water_z(schemeid,stcd,z,tm) values('" ); |
17 | sb.append(t.getSchemeid()).append( "','" ).append(t.getStcd()).append( "','" ); |
18 | sb.append(t.getZ()).append( "','" ).append(fomat.format(t.getTm())).append( "')" ); |
19 | stmt.addBatch(sb.toString()); |
20 | if (iCount % 1000 == 0 ){ |
21 | stmt.executeBatch(); |
22 | stmt.clearBatch(); |
23 | } |
24 | iCount++; |
25 | } |
26 | stmt.executeBatch(); |
27 | stmt.clearBatch(); |
28 | con.commit(); |
29 | long end = System.currentTimeMillis(); |
30 | System.out.println( "addTResultWaterZId used time:" +(end-start)); |
31 | stmt.close(); |
32 | con.close(); |
33 | } catch (SQLException e) { |
34 | try { |
35 | con.rollback(); |
36 | } catch (SQLException e1) { |
37 | e1.printStackTrace(); |
38 | } |
39 | e.printStackTrace(); |
40 | } finally { |
41 | try { |
42 | stmt.close(); |
43 | con.close(); |
44 | } catch (SQLException e) { |
45 | e.printStackTrace(); |
46 | } |
47 | } |