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!