日期:2014-05-20 浏览次数:21591 次
public void test()
{
Connection conn = null;
PreparedStatement pStmt = null;
String sql = "insert into user(uid, screen_name) values(?, ?)";
try {
conn = DB.getConn();
conn.setAutoCommit(false);
pStmt = DB.getpStmt(conn, sql);
pStmt.setString(1, "111111");
pStmt.setString(2, "aaaaaa");
pStmt.addBatch();
pStmt.setString(1, "222222");
pStmt.setString(2, "bbbbbb");
pStmt.addBatch();
pStmt.setString(1, "333333");
pStmt.setString(2, "cccccc");
pStmt.addBatch();
pStmt.setString(1, "333333");
pStmt.setString(2, "dddddd");
pStmt.addBatch();
pStmt.executeBatch();
conn.commit();
} catch (SQLException e) {
e.printStackTrace();
} finally
{
try {
if(pStmt != null)
{
pStmt.close();
}
if(conn != null)
{
conn.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}