jQuery in Action, 2nd edition*
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 Android Security Essentials Live Lessons this week in the Android 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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Java/ SQL-Server- What is wrong with my INSERT?
 
Similar Threads
Language doubt
db2 - 703 certification
DB2 700 and 701 - Test Sample
Packed decimal conversion - Java
Java/ SQL-Server- Saving data to an IMAGE datatype