Re: INSERTINg a Clob in a portable way
- From: "joeNOSPAM@xxxxxxx" <joe.weinstein@xxxxxxxxx>
- Date: Tue, 14 Aug 2007 19:26:16 -0000
On Aug 14, 10:29 am, Thomas Kellerer <FJIFALSDG...@xxxxxxxxxxxxx>
wrote:
Hello,
I'm trying to insert a values for a CLOB column in a portable way. So far using
PreparedStatement.setCharacterStream() together with a Reader to read the CLOB
contents from a local file was working quite well (with various JDBC drivers).
Now I stumbled across a bug in my code that raised it ugly head when using
Apache Derby.
When reading the contents of a file with a multi-byte encoding I can't seem to
find a way to pass the correct length of the data into the setCharacterStream()
method.
What I did so far:
File f = new File("sourcfile.txt");
Reader r = new InputStreamReader(new FileInputStream(f), "UTF-8");
preparedStatement.setCharacterStream(1, r, f.length());
which worked fine for most JDBC drivers except for Derby as Derby (rightfully)
complains that the value supplied (f.length()) does not match the number of
characters read from the stream.
I can't image a way where I can supply the correct length when using a Reader to
supply the Clob content. If I was able to "create" Clob instance in a generic
way, I think this could solve the problem as the Clob interface contains a
setCharacterStream() which does not require a length parameter.
But how would I create the Clob instance if I don't know which driver will be
used at runtime?
Any input appreciated.
Thanks in advance
Thomas
Hi. How about trying setBinaryStream() and send the data as raw bytes?
Joe
.
- Follow-Ups:
- Re: INSERTINg a Clob in a portable way
- From: Thomas Kellerer
- Re: INSERTINg a Clob in a portable way
- References:
- INSERTINg a Clob in a portable way
- From: Thomas Kellerer
- INSERTINg a Clob in a portable way
- Prev by Date: INSERTINg a Clob in a portable way
- Next by Date: Re: INSERTINg a Clob in a portable way
- Previous by thread: INSERTINg a Clob in a portable way
- Next by thread: Re: INSERTINg a Clob in a portable way
- Index(es):
Relevant Pages
|
|