展开全部
Connection con = null;
ResultSet rs = null;
PreparedStatement pst = null;
try {
con = DBCon.getConnection();
con.setAutoCommit(false);
pst = con.prepareStatement(" select * from test ");
rs = pst.executeQuery();
pst = con.prepareStatement(" insert into test1(t1,t2,t3,t4,t5,t6,t7,t8,t9)values(?,?,?,?,?,?,?,?,?) ");
while (rs.next()) {
pst.setString(1, rs.getString(1));
pst.setString(2, rs.getString(2));
pst.setString(3, rs.getString(3));
pst.setString(4, rs.getString(4));
pst.setString(5, rs.getString(5));
pst.setString(6, rs.getString(6));
pst.setString(7, rs.getString(7));
pst.setString(8, rs.getString(8));
pst.setString(9, rs.getString(9));
pst.addBatch();
}
pst.executeBatch();
} catch (SQLException e) {
// TODO: handle exception
} finally {
try {
rs.close();
pst.close();
con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}