1

非常に高いレートで mysql にバッチ挿入を実行しようとしています。パフォーマンスに大きな影響を与える可能性があることを読んだので、 rewriteBatchedStatements 構成オプションを試してみたかったのです。ただし、オプションを追加すると、次の例外が発生します。

java.lang.NullPointerException
at com.mysql.jdbc.PreparedStatement.computeMaxParameterSetSizeAndBatchSize(PreparedStatement.java:1694)
at com.mysql.jdbc.PreparedStatement.computeBatchSize(PreparedStatement.java:1651)
at com.mysql.jdbc.PreparedStatement.executeBatchedInserts(PreparedStatement.java:1515)
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1272)
at com.zaxxer.hikari.proxy.StatementProxy.executeBatch(StatementProxy.java:116)
at com.zaxxer.hikari.proxy.PreparedStatementJavassistProxy.executeBatch(PreparedStatementJavassistProxy.java)

これは挿入を行う私のコードです:

try (Connection connection = DBUtil.getInstance().getConnection();
         PreparedStatement preparedStatement = connection.prepareStatement(query)) {
        connection.setAutoCommit(false);
        for (TransactionBatch batch : batches) {
            try {                   
                preparedStatement.setString(1, batch.getDeviceID());
                preparedStatement.setBinaryStream(2, new ByteArrayInputStream(dataArray));
                preparedStatement.addBatch();
            } catch (Exception e) {
               e.printStackTrace();
            }
        }

        preparedStatement.executeBatch();
    } catch (Exception e) {
        e.printStackTrace();
    }

これは私のjdbc URLです:

jdbc:mysql://url:port/tableName?user=userame&password=password&useServerPrepStmts=false&rewriteBatchedStatements=true

また、接続プールとして HikariCP を使用しています。

編集: 更新 - テーブルに varbinary(10000) 列があることに問題があるようです

4

1 に答える 1