1 import java.sql.*;
 2 public class TestBatch {
 3 
 4 
 5     public static void main(String[] args) throws Exception {
 6         Class.forName("oracle.jdbc.driver.OracleDriver");
 7         Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@192.168.0.1:1521:SXT", "scott", "tiger");
 8         /*
 9         Statement stmt = conn.createStatement();
10         stmt.addBatch("insert into dept2 values (51, '500', 'haha')");
11         stmt.addBatch("insert into dept2 values (52, '500', 'haha')");
12         stmt.addBatch("insert into dept2 values (53, '500', 'haha')");
13         stmt.executeBatch();
14         stmt.close();
15         */
16         
17         PreparedStatement ps = conn.prepareStatement("insert into dept2 values (?, ?, ?)");
18         ps.setInt(1, 61);
19         ps.setString(2, "haha");
20         ps.setString(3, "bj");
21         ps.addBatch();
22         
23         ps.setInt(1, 62);
24         ps.setString(2, "haha");
25         ps.setString(3, "bj");
26         ps.addBatch();
27         
28         ps.setInt(1, 63);
29         ps.setString(2, "haha");
30         ps.setString(3, "bj");
31         ps.addBatch();
32         
33         ps.executeBatch();
34         ps.close();
35         
36         conn.close();
37 
38     }
39   //上面是两种statement进行批处理的例子
40 }
posted on 2012-08-15 14:14  elleniou  阅读(262)  评论(0编辑  收藏  举报