Hello all,
I want to export a field type like BINARY, VARBINARY, LONGVARBINARY
from a table save the result in a file (for example xml) and insert it
later to another table.
Could i read the result with getString() or should i read it with
getBinary and change it then to String to store it in the file?
How do I insert it with PreparedStatement?
Like this:
PreparedStatement pstmt = conn.prepareStatement("INSERT INTO table
('test') VALUES ('?' );
byte[] varByte = xmlValue.getBytes();
pstmt.setBinary(1,varByte);
That doesn't work, i will get some sh...
How do I handle binary-Fields when I like to save it in the time
between export and import?
Thanx to all...
Stefan
joeNOSPAM@BEA.com - 31 May 2006 17:48 GMT
> Hello all,
>
[quoted text clipped - 18 lines]
> Thanx to all...
> Stefan
Hi Stefan. Don't use getString() for binary data. The conversion
from binary to string may involve driver, DBMS, and JVM differences
in charset conversions etc. Get the data as a binary stream or
a byte array so the data is never manipulated. Then you can
transfer it to an appropriate setXXX() call when you want to insert
it via a prepared statement update.
Joe Weinstein at BEA Systems
info@daten-host.de - 31 May 2006 18:07 GMT
thank you joe,
ok my export show's like that:
byte[] byteValue = rSet.getBytes(j);
String value = byteValue.toString();
The value-String I will save in an file.
Later i read the file an import the value like that:
byte[] varByte = value.getByte();
pstmt.setBytes(1, varByte);
But I will get some strange data.
Any idea?
Thank you...
Stefan
joeNOSPAM@BEA.com - 31 May 2006 20:05 GMT
> thank you joe,
>
[quoted text clipped - 14 lines]
> Thank you...
> Stefan
Stop trying to convert byteValue to a string! You have to
store the byte array in a way that doesn't change it.
Do this in one method:
byte[] originalValue = rSet.getBytes(j);
String stringValue = originalValue.toString();
byte[] rebuiltValue = value.getBytes();
Then compare the two arrays, originalValue and rebuiltValue.
Are they exactly the same? Whatever you do, they will have
to be...
Joe