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