VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > 编程开发 > 批处理教程 >
  • Java 最简单的批处理

批处理Batch && PreparedStatement :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import java.sql.*;
 
public class TestBatch {
    
    public static void main(String[] args) throws ClassNotFoundException, SQLException
    {
        Class.forName("com.mysql.jdbc.Driver");
        
        Connection conn = DriverManager.getConnection
        ("jdbc:mysql://localhost/test","root","ZHEN");
        
        /*
        Statement stmt = conn.createStatement();  //执行静态 SQL 语句并返回它所生成结果的对象。
        
        stmt.addBatch("INSERT INTO student VALUES(30,'ddd',12,'ii')");
        stmt.addBatch("INSERT INTO student VALUES(31,'ddd',12,'ii')");
        stmt.addBatch("INSERT INTO student VALUES(32,'ddd',12,'ii')");
        stmt.addBatch("INSERT INTO student VALUES(33,'ddd',12,'ii')");
        
        stmt.executeBatch();
        
        stmt.close();
        
        */
        
        PreparedStatement pstmt =
            conn.prepareStatement("INSERT INTO student VALUES(?,?,?,?)");
        
        pstmt.setInt(140);
        pstmt.setString(2,"qq");
        pstmt.setInt(3,5);
        pstmt.setString(4,"ww");
        pstmt.addBatch();
        
        pstmt.setInt(141);
        pstmt.setString(2,"qq");
        pstmt.setInt(3,5);
        pstmt.setString(4,"ww");
        pstmt.addBatch();
        
        pstmt.setInt(142);
        pstmt.setString(2,"qq");
        pstmt.setInt(3,5);
        pstmt.setString(4,"ww");
        pstmt.addBatch();
        
        pstmt.executeBatch();
        pstmt.close();
        
        conn.close();
        
    }
 
}

  出处:https://www.cnblogs.com/sunxun/p/4701808.html


相关教程