Home > Back-end >  JDBC temporary table insertion of large amount of data and queries
JDBC temporary table insertion of large amount of data and queries

Time:09-17

Of the big data by using the JDBC batch insert time can save time, improve efficiency; The code below
The Connection conn=null;
PreparedStatement ps=null;
SqlSession sqlSession=sqlSessionFactory.openSession();
Try {
Conn=sqlSession. GetConnection ();

If (a list!=null& & List. The size () & gt; 0 {
Conn. SetAutoCommit (false);

Ps=conn. PrepareStatement (
"Insert into table_test" + "(cloumn) values (?) ");
for (int i=0; I & lt; List. The size (); I++) {
Ps. SetString (1, list the get (I));
Ps. The addBatch ();
}

Ps. ExecuteBatch ();
List DetailList=sqlSession. GetMapper (Mapper. The class). The query ();
Conn.com MIT ();
conn.close();
}


} the catch (Exception e) {
e.printStackTrace();
} the finally {
Try {
conn.close();
} the catch (SQLException e) {
//TODO Auto - generated the catch block,
e.printStackTrace();
}
}

With the sqlSession getMapper because if conn is newly generated a session; And temporary table can only be effective in this session, here again the method according to the usual method to invoke the mapper, when you write to a select he is the new open a session, the temporary table data is not detected;
His blind to write, if there is any mistake, please understanding
  • Related