I'm trying to import some data out of my MySQL database using Java, the query returns about 15mill rows and to prevent the ResultSet running out of memory I am streaming each results one by one.
private static void addEdges(DirectedGraph<String, DefaultEdge> g) throws SQLException {
Statement selectID = null;
String selectSQL = "SELECT citations.paperid, papers.id FROM papers INNER JOIN citations ON citations.title = papers.title AND citations.year = papers.year;";
try {
selectID = conn.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY);
selectID.setFetchSize(Integer.MIN_VALUE);
ResultSet rs = selectID.executeQuery(selectSQL);
String from;
String to;
System.out.println("iterating");
while(rs.next()) {
from = rs.getString("paperid");
to = rs.getString("id");
g.addEdge(from, to);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
if (selectID != null) {
try {
selectID.close();
} catch (Exception e) {
System.out.println("Error closing statement");
}
}
}
}
However I'm now getting this error:
Exception in thread "main" java.lang.OutOfMemoryError: GC overhead limit exceeded
at com.mysql.jdbc.MysqlIO.nextRow(MysqlIO.java:2092)
at com.mysql.jdbc.RowDataDynamic.nextRecord(RowDataDynamic.java:406)
at com.mysql.jdbc.RowDataDynamic.next(RowDataDynamic.java:385)
at com.mysql.jdbc.RowDataDynamic.close(RowDataDynamic.java:163)
at com.mysql.jdbc.ResultSetImpl.realClose(ResultSetImpl.java:7472)
at com.mysql.jdbc.ResultSetImpl.close(ResultSetImpl.java:919)
at com.mysql.jdbc.StatementImpl.realClose(StatementImpl.java:2617)
at com.mysql.jdbc.StatementImpl.close(StatementImpl.java:580)
This is being thrown from selectID.close()
Which is odd as the ResultSet it should be closing should only contain one row. Tried allocating more memory but this issue still occurs, any ideas?
(I'm using JGraphT library to create a directed graph)