GBase 8a
其他
文章

gbase8a批量insert代码(JDBC)

发表于2024-06-30 09:11:10245次浏览1个评论

package testsuite.simple.myCase.batchinsert;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.PreparedStatement;

public class InsertTest {

public static void main(String[] args) {

//批量插入开启rewriteBatchedStatements=true参数可以重写insert语句,提高性能

String url="jdbc:gbase://192.168.5.85:5258/bht?user=gbase&password=gbase20110531&rewriteBatchedStatements=true";

try {

Class.forName("com.gbase.jdbc.Driver");

Connection conn = DriverManager.getConnection(url);

String sql="insert into fulltype (aint,bfloat,cdouble) values(?,?,?)";

PreparedStatement pst = conn.prepareStatement(sql);

for(int i=0;i<100;i++){

pst.setInt(1, i);

pst.setFloat(2, i);

pst.setDouble(3,i);

pst.addBatch();

if(i%50==0){

//根据实际使用,修改多少条一提交

pst.executeBatch();

pst.clearBatch();

}

}

pst.executeBatch();

} catch (Exception e) {

e.printStackTrace();

}

}

}

评论

登录后才可以发表评论
用户头像
levvel发表于 8个月前
听说评论可以拿积分,我试一下子