zoukankan      html  css  js  c++  java
  • jdbc批处理进行多条数据插入

    package cn.linjun.demo;
    
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.SQLException;
    import java.sql.Statement;
    
    public class DemoBrach {
    
        private static Connection connection;
        private static Statement statement;
    
        public static void main(String[] args) {
            try {
                Class.forName("com.mysql.jdbc.Driver");
                connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/user", "root", "root");
                connection.setAutoCommit(false);
                statement = connection.createStatement();
                for (int i=1;i<100;i++){     //同时插入100条数据
                    statement.addBatch("insert into user1 values (null,'lideng"+i+"',20000)");
    
                }
                statement.executeBatch();
                connection.commit();
            } catch (Exception e) {
                e.printStackTrace();
            }finally {
                if(statement!=null){
                    try {
                        statement.close();
                    } catch (SQLException e) {
                        e.printStackTrace();
                    }
                }
                if (connection!=null){
                    try {
                        connection.close();
                    } catch (SQLException e) {
                        e.printStackTrace();
                    }
                }
            }
    
    
        }
    }
  • 相关阅读:
    position中的四种属性
    CSS中link和@import的区别
    隐藏对应元素的办法
    word20161217
    word20161216
    word20161215
    word20161214
    word20161213
    word201612012
    word20161211
  • 原文地址:https://www.cnblogs.com/qurui1998/p/10685858.html
Copyright © 2011-2022 走看看