日期:2014-05-20 浏览次数:20921 次
public class Tc3p0 {
public static void main(String[] args) {
Connection con = getConnection();Statement st=null;ResultSet rs=null;
int cnt=0;
try {
con.setAutoCommit(false);
for(int i=0;i<100;i++){
String sql = "insert into users (name) values("+i+")";
st= con.createStatement();
st.addBatch(sql);
cnt++;
Thread.sleep(5000);
if(cnt%3==0){
st.executeBatch();
con.commit();
st.clearBatch();
}
}
st.executeBatch();
con.commit();
st.clearBatch();
} catch (Exception e) {
e.printStackTrace();
}
}
private static ComboPooledDataSource ds = new ComboPooledDataSource();
public static Connection getConnection() {
try {
return ds.getConnection();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
}
for(int i=0;i<100;i++){
String sql = "insert into users (name) values("+i+")";
st= con.createStatement();
st.executeUpdate(sql);
cnt++;
if(cnt%3==0){
con.commit();
}
}