This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes JDBC and the fly likes Java/ SQL-Server- What is wrong with my INSERT? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Java/ SQL-Server- What is wrong with my INSERT?" Watch "Java/ SQL-Server- What is wrong with my INSERT?" New topic
Author

Java/ SQL-Server- What is wrong with my INSERT?

Monty Guppy
Ranch Hand

Joined: Sep 15, 2001
Posts: 49
Here I convert a String into a bytearray before loading it into a MS SQL Server table. The byte array is to be stored in a field of datatype=IMAGE. The 3 fields of the table are:
rpt_id (char)
rpt_name (char)
rpt_data (IMAGE)
The code looks like this:
String fileData="A,B,C,D,E";
byte[] defaultBytes = filedata.getBytes();
String insertSQL = "INSERT INTO reports (rpt_id,rpt_name,rpt_data) VALUES ('100','TEST_REPORT'," + defaultBytes + ")";
java.sql.SQLException: [LOUSQL14]Unclosed quotation mark before the character string 'B@2c33ee96)'
The above update works if I put defaultBytes within quotes like this:
String insertSQL = "INSERT INTO reports (rpt_id,rpt_name,rpt_data) VALUES ('100','TEST_REPORT','" + defaultBytes + "')";
However the problem in this case (I think) is that the bytes gets stored as a textual (literal) value like B@2c33ee96. So when I return the data lateron and convert the bytearray to a string, the string="B@2c33ee96", rather than ="A,B,C,D,E"
Please help.
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
This seems to be more of a JDBC question, so I'm moving it there. In fact you've already posted sopmething like this here, but this post seems to have more useful info in it., so I'll keep it and close the earlier one. Please don't spread your questions out across multiple forums. Thanks.


"I'm not back." - Bill Harding, Twister
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java/ SQL-Server- What is wrong with my INSERT?