GBase8s jdbc批量插入数据的正确方法
GBase8s jdbc实现了标准的批量插入接口,与其他数据库厂商使用方式一致,降低了使用成本。再次基础上还新增了一个url参数用于提升批量插入性能,通过开启该参数在网络友好的情况下通过降低交互次数提升性能。首先介绍参数如下:
IFX_USEPUT=1:开启性能优化,提升插入性能
IFX_USEPUT=0:默认值,不开启优化。
下面结合测试用例讲解批量插入的标准方式。
1、用例如下:
public static void main(String[] args) throws Exception {
String url = "jdbc:gbasedbt-sqli://localhost:19088/zhtest:GBASEDBTSERVER=gbase01;DB_LOCALE=zh_CN.utf8;CLIENT_LOCALE=zh_CN.utf8;IFX_USEPUT=1;" +
"PROTOCOLTRACE=5;PROTOCOLTRACEFILE=./trace.log"
;
String username = "gbasedbt";
String password = "GBase123";
Class.forName("com.gbasedbt.jdbc.Driver");
Connection conn = DriverManager.getConnection(url,username,password);
select(conn);
conn.close();
}
private static void select(Connection conn) throws SQLException {
conn.createStatement().execute("truncate table test1");
PreparedStatement pst = conn.prepareStatement("insert into test1 (col1,col2) values(?,?)");
System.out.println("begin");
long a = System.currentTimeMillis();
for(int i=0;i<10;i++){
for(int j=0;j<10000;j++){
pst.setInt(1,j);
pst.setString(2,"test");
pst.addBatch();
}
pst.executeBatch();
pst.clearBatch();
}
long b = System.currentTimeMillis();
System.out.println((b-a)/1000);
System.out.println("end");
pst.close();
}
热门帖子
- 12025-12-01浏览数:182759
- 22023-05-09浏览数:25044
- 42023-09-25浏览数:18519
- 52020-05-11浏览数:17526