• Java 最简单的批处理


    批处理Batch && PreparedStatement :

    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(1, 40);
    		pstmt.setString(2,"qq");
    		pstmt.setInt(3,5);
    		pstmt.setString(4,"ww");
    		pstmt.addBatch();
    		
    		pstmt.setInt(1, 41);
    		pstmt.setString(2,"qq");
    		pstmt.setInt(3,5);
    		pstmt.setString(4,"ww");
    		pstmt.addBatch();
    		
    		pstmt.setInt(1, 42);
    		pstmt.setString(2,"qq");
    		pstmt.setInt(3,5);
    		pstmt.setString(4,"ww");
    		pstmt.addBatch();
    		
    		pstmt.executeBatch();
    		pstmt.close();
    		
    		conn.close();
    		
    	}
    
    }
    

      

  • 相关阅读:
    linux getch()实现
    cppcheck 下载与安装(Liunx)
    apt-get 命令
    nanopb 文档
    VS调试技术
    c 单元测试 check
    GDB 调试
    GCC选项 –I,-l,-L
    作业66
    zhuoye
  • 原文地址:https://www.cnblogs.com/sunxun/p/4701808.html
Copyright © 2020-2023  润新知