GBase 8s
运维管理
文章

GBase8s jdbc批量插入数据的正确方法

发表于2025-12-18 09:57:4543次浏览7个评论

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();

}

评论

登录后才可以发表评论
用户头像
GBase用户28017发表于 7个月前
好文。
枫溪发表于 7个月前
1
枫溪发表于 7个月前
2
枫溪发表于 7个月前
4
枫溪发表于 7个月前
5
枫溪发表于 7个月前
3
用户头像
柒柒天晴发表于 2个月前
厉害了