Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>A file would work (I definitely woudln't do a per pixel call, you'll be waiting hours for the result). You just need a buffer. Break the application apart along the lines of -></p> <pre><code>int[] buffer = new int[BUFFER_SIZE]; ResultSet data = ....; //Forward paging result set while(true) { for(int i = 0; i &lt; BUFFER_SIZE; i++) { //Read result set into buffer } //write buffer to cache (HEAP/File whatever) if(resultSetDone) break; } </code></pre> <p>Read the documentation on your database driver, but any major database is going to optimize your ResultSet object so you can use a cursor and not worry about memory.</p> <p>All that being said... an int[10000][10000] isn't why you're running out of memory. Its probably what you're doing with those values and your algorithm. Example:</p> <pre><code>public class Test { public static void main(String... args) { int[][] ints = new int[10000][]; System.out.println(System.currentTimeMillis() + " Start"); for(int i = 0; i &lt; 10000; i++) { ints[i] = new int[10000]; for(int j = 0; j &lt; 10000; j++) ints[i][j] = i*j % Integer.MAX_VALUE / 2; System.out.print(i); } System.out.println(); System.out.println(Integer.valueOf(ints[500][999]) + " &lt;- value"); System.out.println(System.currentTimeMillis() + " Stop"); } } </code></pre> <p>Output -></p> <pre><code>1344554718676 Start //not even listing this 249750 &lt;- value 1344554719322 Stop </code></pre> <p>Edit--Or if I misinterpreted your question try this -> <a href="http://www.java2s.com/Code/Java/Database-SQL-JDBC/LoadimagefromDerbydatabase.htm" rel="nofollow">http://www.java2s.com/Code/Java/Database-SQL-JDBC/LoadimagefromDerbydatabase.htm</a></p> <p>I see... well take a look around, I'm rusty but this seems to be a way to do it. I'd double check my buffering...</p> <pre><code>import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; public class Test { public static void main(String... args) { // 2 ^ 24 bytes, streams can be bigger, but this works... int size = Double.valueOf((Math.floor((Math.pow(2.0, 24.0))))).intValue(); byte[] bytes = new byte[size]; for(int i = 0; i &lt; size; i++) bytes[i] = (byte) (i % 255); ByteArrayInputStream stream = new ByteArrayInputStream(bytes); File file = new File("test.io"); //kill the hard disk //Crappy error handling, you'd actually want to catch exceptions and recover BufferedInputStream in = new BufferedInputStream(stream); BufferedOutputStream out = null; byte[] buffer = new byte[1024 * 8]; try { //You do need to check the buffer as it will have crap in it on the last read out = new BufferedOutputStream(new FileOutputStream(file)); while(in.available() &gt; 0) { int total = in.read(buffer); out.write(buffer, 0, total); } } catch (IOException e) { e.printStackTrace(); } finally { if(out != null) try { out.flush(); out.close(); } catch (IOException e) { e.printStackTrace(); } } System.out.println(System.currentTimeMillis() + " Start"); System.out.println(); System.out.println(Integer.valueOf(bytes[bytes.length - 1]) + " &lt;- value"); System.out.println("File size is-&gt; " + file.length()); System.out.println(System.currentTimeMillis() + " Stop"); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload