• Java(34)_ 用JDBC批量向数据库插入语句


    package mysql;
    import java.sql.DriverManager;
    import java.sql.*;
    
    /**
     * 连接数据库,加载数据库。
     *
     *
     */
    public class MyTable {
        public static void main(String[] args) throws SQLException {
    
            String user = "fabu";
            String password = "bowen@123";
            String url = "jdbc:mysql://10.37.153.4:3306/rdrssit_4?user=fabu&password=bowen815@123&useSSL=false&useUnicode=true&characterEncoding=UTF8";
            String driver = "com.mysql.jdbc.Driver";
            PreparedStatement pst = null;
            Connection conn = null;
            try {
                // 1 加载驱动包
                Class.forName(driver);
                conn = DriverManager.getConnection(url);
                if (!conn.isClosed()) {
                    System.out.println("Success database connection! ");
                } else {
                    System.out.println("Failed to connect to database");
                }
                // 2  sql语句
                String sql = "insert into test_table01 values(?, b'1', 11, 11, 11, 11, 11, '11.111111', '11.111111',"
                        + " '11.111', '11.1111', '测试char_11', '测试varchar_11','2000-01-11', '2011', '2000-01-11 00:00:11', "
                        + "'测试text_11', '00:00:11', '00:00:01.1', '00:00:00.011','00:00:00.000011', '2000-01-11 00:00:11', "
                        + "'2000-01-11 00:00:01.1', '2000-01-11 00:00:00.011','2000-01-11 00:00:00.000011')";
                pst = conn.prepareStatement(sql);
                // 3  执行sql语句,批量插入语句
                for(int i=5;i<=100;i++){
                    pst.setInt(1,i);
                    pst.executeUpdate();
                }
                 // pst.setInt(1,4);
                 // pst.executeUpdate();
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            } finally {
                // 6 关闭连接,
                  pst.close();
                  conn.close();
    } } }
  • 相关阅读:
    Activiti-流程定义
    Activiti入门案例
    工作流--Activiti
    并发编程面试题
    CAS无锁机制
    Activiti个人流程和流量变化
    工作流——Activiti案例
    工作流——Activiti
    并发编程面试题
    锁机制-AQS和CAS
  • 原文地址:https://www.cnblogs.com/sunnybowen/p/9879532.html
Copyright © 2020-2023  润新知