用java写了一个小工具,用来执行.sql文件
做了次测试,如果.sql文件有一万条insert语句的时候不报错,也不更新数据库。(更新的是postgres数据库,拷出来再postgres里可以执行)
java的代码是:
Configuration config = new Configuration(DBConfigName);
Connection conn = ConnectionUtil.getConnection(config);
PreparedStatement ps;
try {
ps = conn.prepareStatement(sql.toString());
ps.execute();
ps.close();
                    ....
                    }
                    ....
public static Connection getConnection(Configuration config) throws DatabaseRuntimeException {

Connection con;
try{
Class.forName(config.getDriverName());
con = DriverManager.getConnection(
        config.getUrl(), 
        config.getUsername(), 
        config.getPassword()); con.setAutoCommit(false);
return con;
} catch(Exception e) {
throw new DatabaseRuntimeException(e);
}
}
那位高手指正以下,谢谢!

解决方案 »

  1.   

    don't forget to COMMIT!
      

  2.   

    楼上的说得对。
    conn.commit();
      

  3.   

    应该不是COMMIT的问题,不然楼主说的"如果是1000条数据的时候,可以执行成功"那是如何办到的.
      

  4.   

    建议先把commit去掉,然后在看看能不能入库!
      

  5.   

    嗯,做了commit,是执行太多数据操作的时候就没反应了,我觉得是这个execute()的问题。会不会这里面有什么容量控制。
      

  6.   

    to baige1210(小白):
    嗯,commit操作是在最后面做的,但我debug的时候走到ps.execute();的时候就停掉了。
      

  7.   

    数据太多有可能导致connection溢出(猜测)
    比如1000万条要一下commit需要内存量就很大了
    不如试一下每1000条commit一下看看效果在做优化