2 messages in com.mysql.lists.javaRe: Strange problem of setBinaryStrea...| Subject: | Re: Strange problem of setBinaryStream and executeUpdate in PreparedStatement![]() |
|---|---|
| From: | J. Wang (jwa...@frdc.fujitsu.com) |
| Date: | 06/20/2004 06:22:14 PM |
| List: | com.mysql.lists.java |
Who can help me?
Thanks
----- Original Message -----
From: "J. Wang" <jwa...@frdc.fujitsu.com>
To: <ja...@lists.mysql.com>
Sent: Friday, June 18, 2004 3:49 PM
Subject: Strange problem of setBinaryStream and executeUpdate in
PreparedStatement
Hi,
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.
I will appreciate any suggestion. Thanks in advance!
Regards,
J. Wang




