Re: ps.setCharacterStream() and memory usage - Mailing list pgsql-jdbc

From Vadim Nasardinov
Subject Re: ps.setCharacterStream() and memory usage
Date
Msg-id 200411021155.22490@vadim.nasardinov
Whole thread Raw
In response to ps.setCharacterStream() and memory usage  (Sebastiaan van Erk <sebster@sebster.com>)
List pgsql-jdbc
On Friday 29 October 2004 07:56, Sebastiaan van Erk wrote:
>    ps.setCharacterStream(1, reader, (int) messageFile.length());
>    ps.executeUpdate();
>
> The reason I do this (using a character stream to load a text file
> to a TEXT field) is that I wish to avoid loading the file into
> memory completely.

By doing this, you may overallocate.  Note that File#length() [1]
returns the length of the file in _bytes_.
AbstractJdbc2Statement#setCharacterStream uses the passed in number to
allocate a _character_ array of that length.  If your file is encoded
in, say, UTF-16, its byte length is twice its character length.  Half
of the character array allocated by the setCharacterStream method is
wasted in this case.


Vadim


Footnotes

  1. http://java.sun.com/j2se/1.4.2/docs/api/java/io/File.html#length%28%29


pgsql-jdbc by date:

Previous
From: Ron St-Pierre
Date:
Subject: Re: JDeveloper
Next
From: Alan Stange
Date:
Subject: Re: executeBatch() issue with new driver?