JDBC and ResultSet problem
From: Peter L Skoglund (peter.skoglund_at_gmail.com)
Date: 03/09/05
- Next message: Luke Webber: "Re: ODB (Cache?) vs ORM"
- Previous message: John: "Re: how to make 'rolling tables'"
- Next in thread: joeNOSPAM_at_BEA.com: "Re: JDBC and ResultSet problem"
- Reply: joeNOSPAM_at_BEA.com: "Re: JDBC and ResultSet problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 9 Mar 2005 01:41:04 -0800
Dear all,
When trying to output a rather large database (around 10M rows) to a
textfile I get a memory problem that I guess has to do with the
ResaultSet (see a part of the code below). Is there any way in java to
get data direcly from the db NOT using ResultSet, something like a
datareader or connect a stream directly to the db allowing to read
line by line or even smaller parts? In my case there is no way I can
extend the memory sapce.
Regards
Peter
/* ----------------------- BEGIN CODE PART ----------------------- */
Class.forName(driverName);
System.out.println("Opening db connection");
connection = DriverManager.getConnection(url, user,
passwd);
stmt = connection.createStatement();
//Execute query
try {
//TODO Find a better way to stream data, NOT using
ResultSet
stmt.getResultSet();
rs = stmt.executeQuery(query);
System.out.println("ResultSet OK");
//Write information to file
FileOutputStream out;
PrintStream p;
try
{
out = new FileOutputStream(fileName);
System.out.println("Printing data to file...");
p = new PrintStream(out);
while (rs.next())
{
p.println(rs.getString(1));
myrowcounter +=1;
}
p.close();
System.out.println("File printed with " + myrowcounter + "
rows");
}
/* ------------------------ END CODE PART ------------------------ */
- Next message: Luke Webber: "Re: ODB (Cache?) vs ORM"
- Previous message: John: "Re: how to make 'rolling tables'"
- Next in thread: joeNOSPAM_at_BEA.com: "Re: JDBC and ResultSet problem"
- Reply: joeNOSPAM_at_BEA.com: "Re: JDBC and ResultSet problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]