private static void test3(){
Connection conn = null;
String dbDriver = "org.sqlite.JDBC" ;
String dbPath = "d:/test.ite";
PreparedStatement ps = null;
String sql = "insert into t1 values (?,?,?,?,?)";
try {
Class.forName( dbDriver ).newInstance();
conn = DriverManager.getConnection( "jdbc:sqlite:/" + dbPath );
long t = System.currentTimeMillis();
//conn.setAutoCommit(false);
ps = conn.prepareStatement(sql);
for(int j = 0; j < 100; j++){
for(int i= 0; i< 5 ; i++){
ps.setString(i+1, j+"" +i);
}
ps.addBatch();
}
int[] ret = ps.executeBatch();
ps.clearBatch();
//conn.commit();
//conn.setAutoCommit(true);
long t2 = System.currentTimeMillis();
System.out.println(t2-t);
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
SQLite数据库JDBC优化:
手动控制事务,否则默认为每次执行一次SQL提交一次事务。会造成系统性能下降,SQLite数据库中表现尤为明显。