亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

JDBC批量插入性能

JDBC批量插入性能

絕地無雙 2019-08-06 17:13:48
JDBC批量插入性能我需要在mysql數據庫中插入幾億條記錄。我一次批量插入100萬。請參閱下面的代碼。這看起來很慢。有沒有辦法優化它?try {         // Disable auto-commit         connection.setAutoCommit(false);         // Create a prepared statement         String sql = "INSERT INTO mytable (xxx), VALUES(?)";         PreparedStatement pstmt = connection.prepareStatement(sql);         Object[] vals=set.toArray();         for (int i=0; i<vals.length; i++) {             pstmt.setString(1, vals[i].toString());             pstmt.addBatch();         }         // Execute the batch         int [] updateCounts = pstmt.executeBatch();         System.out.append("inserted "+updateCounts.length);
查看完整描述

3 回答

?
當年話下

TA貢獻1890條經驗 獲得超9個贊

我有一個與mysql類似的性能問題,并通過在連接url中設置useServerPrepStmtsrewriteBatchedStatements屬性來解決它。

Connection c = DriverManager.getConnection("jdbc:mysql://host:3306/db?useServerPrepStmts=false&rewriteBatchedStatements=true", "username", "password");


查看完整回答
反對 回復 2019-08-06
  • 3 回答
  • 0 關注
  • 950 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號