Re: JDBC ResultSet writes to tmp file



Hong wrote:
> The problem I got is when I am using the ResultSet to loop through the
> result rows, the JDBC driver keeps writing each row's data to a tmp
> file at /Tomcat/temp/ After the loop is finished, I do a
> "ResultSet.close();". After that, the content in that tmp file is
> gone.
>
> Because the content written to the tmp file is really big during the
> looping, it significantly slows done the performance.

Did you actually verify this with some measurements that the tmp file is
the reason for slow performance?

> Following is my
> code.
> [code]
> int size = 0;
> int i = 0;
> ObjectOutputStream outputToApplet = new
> ObjectOutputStream(response.
> getOutputStream());
> ResultSet resultSet = statement.executeQuery(q);
>
> if (page == 0) { //send back the number of rows.
> resultSet.last();
> size = resultSet.getRow();
> resultSet.beforeFirst();
>
> outputToApplet.writeObject(new Integer(size));
> outputToApplet.flush();
> }
> else if (page > 0) { //send back 1000 as the number of
> rows, and start from page*1000
> outputToApplet.writeObject(new Integer(1000));
> outputToApplet.flush();
> resultSet.absolute(page * 1000);
> }
>
> while (resultSet.next()) {
> String MailID = resultSet.getString("mail_Id");
> String Name = resultSet.getString("mailFrom");
> String To = resultSet.getString("mailToSorted");
> String Subject = resultSet.getString("Subject");
> String InsertDate = resultSet.getString("insertDate");
>
> CustomerServiceReturn C = new
> CustomerServiceReturn(Name, To, MailID, Subject, InsertDate);
>
> outputToApplet.writeObject(C);
> outputToApplet.flush();
>
> i++;
> if (i == 1000) {
> outputToApplet.close();
> resultSet.close();
> return;
> }
> }
>
> resultSet.close();
> outputToApplet.close();
> [/code]
> The name of the file is "ddtbxxxxx.tmp". xxxxx is a number.
>
> Thank you so much for any help.

I'd remove the invocations of "outputToApplet.flush();". Closing does a
flush automatically and with the flushes in between you underutilize the
streams buffers which might be *one* reasons for bad performance.

It's also a good idea to put close() calls into finally blocks. That way
you make sure that even in case of an exception resources are properly
deallocated.

Kind regards

robert

.



Relevant Pages

  • Re: How to launch an Executable from within memory
    ... I came across this problem when writing a program uninstaller that was ... Write an .EXE file to the Temporary Files directory, ... Execute the .TMP file. ... Delete the caller and the directory in which the caller was. ...
    (microsoft.public.win32.programmer.kernel)
  • Re: 1352 NUL bytes at the end of a page? (was Re: Assertion `s && s->tree failed: The sag
    ... No, no, I'm not claiming that _you_ are writing the NUL bytes. ... > elsewhere, we are writing to a tmp file, the tmp file is NOT mmapped. ... "write" calls can trigger it through the "commit_write" function. ... send the line "unsubscribe linux-kernel" in ...
    (Linux-Kernel)
  • Re: Conventions for writing files to /tmp
    ... > You should consider not writing into /tmp. ... >> no other process will clobber it by coincidentally writing a tmp file ... > Using own tmp directories makes that naming topic less of a problem. ... > Name and PID should suffice if you take care to remove the temporaries ...
    (comp.unix.shell)
  • JDBC ResultSet writes to tmp file
    ... The problem I got is when I am using the ResultSet to loop through the ... the JDBC driver keeps writing each row's data to a tmp ... Because the content written to the tmp file is really big during the ...
    (microsoft.public.sqlserver.jdbcdriver)

Loading