用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);
}
}
那位高手指正以下,谢谢!
做了次测试,如果.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);
}
}
那位高手指正以下,谢谢!
conn.commit();
嗯,commit操作是在最后面做的,但我debug的时候走到ps.execute();的时候就停掉了。
比如1000万条要一下commit需要内存量就很大了
不如试一下每1000条commit一下看看效果在做优化