If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Strange problem of setBinaryStream and executeUpdate in PreparedStatement

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-18-04, 09:27
hustwj hustwj is offline
Registered User
 
Join Date: Jun 2004
Posts: 2
Strange problem of setBinaryStream and executeUpdate in PreparedStatement

Following is the part of my code which inserts blob data into the database.

/////// code snippet //////////
String str1 = "test1";
String str2 = "test2";

//"1.gz" is a compressed Chinese Web page less than 64k.
File f = new File("./1.gz");
FileInputStream fis = new FileInputStream(f);

String insert_sql = "INSERT INTO Test (col1,col2,col3) VALUES(?,?,?)";
PreparedStatement ps = conn.prepareStatement(insert_sql);
ps.setString(1,str1);
ps.setString(2,str2);
ps.setBinaryStream(3,fis,(int)(f.length()));
ps.executeUpdate();
/////////////////////////////////

But output is very strange as follows:
===============================================
java.sql.SQLException: Syntax error or access violation, message from server: "
You have an error in your SQL syntax near '?x???z???????y?5???????
?????EA???h1?r??Q????\\~??S????' at line 1"

In my debug step by step, I found the problem is in the ps.setBinaryStream and ps.executeUpdate.

Table Test
-----------------
col1 varchar
col2 varchar
col3 blob
-----------------

my development environment
-----------------------------------------------------------------
j2sdk1.4.2_04 on winxp
mysql-connector-java-3.0.14-production-bin.jar
Mysql server version: 3.23.39 on Sun solaris 8
Mysql server version: 4.0.15-log on Redhat Linux Advanced server
-----------------------------------------------------------------


I have searched and checked how to solve this problem on the mailing list and forums for 2 days, and I found someone also met the similar problem in the some forums before, but nobody solves this problem finally.


Thanks in advance!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On