I am getting this error:
Exception in thread \"main\" java.lang.OutOfMemoryError: Java heap space
at com.mysql.jdbc.MysqlIO.nextRowFast(MysqlIO.java:1585
You don't need to worry about -Xms too much - that's the initial Heap size on startup.
-Xmx is the max Heap size. Try increasing it until either you don't get the OutOfMemory exception anymore, or until you run out of memory.
If you run out of memory, you can't load the entire ResultSet at once, and you'll need to apply the approaches that others have mentioned.