package test;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import common.DbUtils;
public class BatchTest {
public static void main(String[] args) {
testBatch();
}
public static void testBatch(){
Connection conn=null;
PreparedStatement pstmt=null;
conn=DbUtils.getConnection();
String sql="insert into product(name,price)values(?,?)";
try {
pstmt=conn.prepareStatement(sql);
pstmt.setString(1, "mp13");
pstmt.setDouble(2, 500.00);
pstmt.addBatch();
pstmt.setString(1, "mp14");
pstmt.setDouble(2, 600.00);
pstmt.addBatch();
pstmt.addBatch("update product set name='mp13' where id=9");
pstmt.addBatch();
pstmt.executeBatch();
} catch (SQLException e) {
e.printStackTrace();
}finally{
DbUtils.close(pstmt, conn);
}
}
}
转载于:https://my.oschina.net/u/2356966/blog/418166