JDBC导入
当前SelectDB Cloud支持JDBC,调用beigin insert commit的方式导入数据
使用示例
SQL示例
begin;
insert into db.tbl values(),(),();
insert into db.tbl values(),(),();
insert into db.tbl values(),(),();
commit;
JDBC示例
public static void main(String[] args) throws Exception {
//单次导入insert语句的数量
int insertNum = 10;
//单条insert攒批的数量
int batchSize = 10000;
String URL="jdbc:mysql://127.0.0.1:9030/test_db?useLocalSessionState=true";
Connection connection = DriverManager.getConnection(URL, "admin", "password");
Statement statement = connection.createStatement();
statement.execute("begin");
//拼接多条insert语句
for (int num = 0; num < insertNum; num++) {
StringBuilder sql = new StringBuilder();
sql.append("insert into test_tbl values ");
for(int i = 0; i < batchSize; i++){
if(i > 0){
sql.append(",");
}
//拼接一行数据,如:姓名,年龄。可根据具体业务修改
sql.append("('zhangsan',18)");
}
//add sql to batch: insert into tbl values(),(),()
statement.addBatch(sql.toString());
}
statement.addBatch("commit");
statement.executeBatch();
//关闭资源
statement.close();
connection.close();
}
性能测试
通过上面的JDBC导入程序,在SelectDB Cloud的Medium(16c64G)*1集群下,单条数据为1KB的时,30并发可达到12w/s的写入。