Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / May 2006

Tip: Looking for answers? Try searching our database.

BINARY

Thread view: 
info@daten-host.de - 31 May 2006 17:32 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.