zoukankan      html  css  js  c++  java
  • C# 批量插入Mysql zt 武胜

    public void loadData(Connection connection)
    {
        long starTime = System.currentTimeMillis();
     
        String sqlString = "load data local infile ? into table test";
        PreparedStatement pstmt;
        try {
            pstmt = connection.prepareStatement(sqlString);
             
            pstmt.setString(1, "tfacts_result");
             
            pstmt.executeUpdate();
             
            pstmt.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
         
        long endTime = System.currentTimeMillis();
         
        System.out.println("program runs " + (endTime - starTime) + "ms");
     
    }
     
     
    public static void mysql_batch(string sqlStr,int point)
            {
                string sql = "insert into test(node1, node2, weight) values(?, ?, ?)";
    
                Connection conn = getConn("mysql");
                conn.setAutoCommit(false);
                //clear(conn);
                try
                {
                    PreparedStatement prest = conn.prepareStatement(sql);
                    //long a = System.currentTimeMillis();
                    for (int x = 1; x <= count; x++)
                    {
                        prest.setInt(1, x);
                        prest.setString(2, "张三");
                        prest.addBatch();
                        if (x % point == 0)
                        {
                            prest.executeBatch();
                            conn.commit(); 
                        }
                    }
                    prest.close();
                    //long b = System.currentTimeMillis();
                    //print("MySql批量插入10万条记录", a, b, point);
                }
                catch (Exception ex)
                {
                    ex.printStackTrace();
                }
                finally
                {
                    close(conn);
                }
  • 相关阅读:
    httpd-2.2 配置及用法完全攻略
    在 Ubuntu 16.04 上安装 LEMP 环境之图文向导
    Zookeeper集群搭建
    smem – Linux 内存监视软件
    X.Org可能将失去它的域名x.org
    Docker 容器测试全探索
    Unix操作系统中UUCP知识详细讲解
    常用的Git Tips
    Unix操作系统中UUCP知识详细讲解
    将博客搬至CSDN
  • 原文地址:https://www.cnblogs.com/zeroone/p/3062488.html
Copyright © 2011-2022 走看看