開始行: * キーワード [#gae867ec] - MySQL - PreparedStatement - ResultSet - OutOfMemoryError * 現象 [#u465d824] 一行ずつResultSetからデータ取得しているはずなのにOutOfMem... Exception in thread "main" java.lang.OutOfMemoryError: J... at com.mysql.jdbc.MysqlIO.nextRowFast(MysqlIO.java:1649) at com.mysql.jdbc.MysqlIO.nextRow(MysqlIO.java:1426) at com.mysql.jdbc.MysqlIO.readSingleRowSet(MysqlIO.java... at com.mysql.jdbc.MysqlIO.getResultSet(MysqlIO.java:477) at com.mysql.jdbc.MysqlIO.readResultsForQueryOrUpdate(M... at com.mysql.jdbc.MysqlIO.readAllResults(MysqlIO.java:1... at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2... at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl... at com.mysql.jdbc.PreparedStatement.executeInternal(Pre... at com.mysql.jdbc.PreparedStatement.executeQuery(Prepar... * 原因 [#u0c975fb] すべての行をfetchしてResultSetを生成しようとするようです... 一行ずつ取得するようにした実装が泣くね。 * 対策 [#l85799df] 一定行ずつfetchするようにMySQLを設定します。 ** 接続プロパティで指定する方法 [#bc1e7393] 次のクエリストリングを接続プロパティに加えます。 useCursorFetch=true&defaultFetchSize=100 100は一度にfetchする行数のよう。なので様子みて適宜。 ** コードで指定する方法 [#a153f6e9] stmt = conn.createStatement( java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY ); stmt.setFetchSize(Integer.MIN_VALUE); * 備考 [#o02ff04d] PreparedStetementもデフォルトではPreparedしてないというと... * 参考 [#oa2bd815] - [[Connector/J でOutOfMemoryError | ビズリーチラボ>http:... - [[sqoopでOutOfMemoryError - wyukawa’s blog>http://d.hat... - [[exception - Java Heap Memory error - Stack Overflow>h... - [[OutOfMemoryError: Java heap space [Archive] - Lavast... 終了行: * キーワード [#gae867ec] - MySQL - PreparedStatement - ResultSet - OutOfMemoryError * 現象 [#u465d824] 一行ずつResultSetからデータ取得しているはずなのにOutOfMem... Exception in thread "main" java.lang.OutOfMemoryError: J... at com.mysql.jdbc.MysqlIO.nextRowFast(MysqlIO.java:1649) at com.mysql.jdbc.MysqlIO.nextRow(MysqlIO.java:1426) at com.mysql.jdbc.MysqlIO.readSingleRowSet(MysqlIO.java... at com.mysql.jdbc.MysqlIO.getResultSet(MysqlIO.java:477) at com.mysql.jdbc.MysqlIO.readResultsForQueryOrUpdate(M... at com.mysql.jdbc.MysqlIO.readAllResults(MysqlIO.java:1... at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2... at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl... at com.mysql.jdbc.PreparedStatement.executeInternal(Pre... at com.mysql.jdbc.PreparedStatement.executeQuery(Prepar... * 原因 [#u0c975fb] すべての行をfetchしてResultSetを生成しようとするようです... 一行ずつ取得するようにした実装が泣くね。 * 対策 [#l85799df] 一定行ずつfetchするようにMySQLを設定します。 ** 接続プロパティで指定する方法 [#bc1e7393] 次のクエリストリングを接続プロパティに加えます。 useCursorFetch=true&defaultFetchSize=100 100は一度にfetchする行数のよう。なので様子みて適宜。 ** コードで指定する方法 [#a153f6e9] stmt = conn.createStatement( java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY ); stmt.setFetchSize(Integer.MIN_VALUE); * 備考 [#o02ff04d] PreparedStetementもデフォルトではPreparedしてないというと... * 参考 [#oa2bd815] - [[Connector/J でOutOfMemoryError | ビズリーチラボ>http:... - [[sqoopでOutOfMemoryError - wyukawa’s blog>http://d.hat... - [[exception - Java Heap Memory error - Stack Overflow>h... - [[OutOfMemoryError: Java heap space [Archive] - Lavast... ページ名: