OS:windows7
MySQL:5.0code:package com.hgd.richard.jdbc;import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;public class MyBlobTest { public static void main(String[] args) throws Exception {
insert();
}

static void insert() throws Exception{
Class.forName("com.mysql.jdbc.Driver");

Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/jdbc", "root",      "mysql");
//blob_test为表名,id为自动增长型,big_bit为blob型
PreparedStatement ps = conn.prepareStatement("insert into blob_test(big_bit) values(?)");

File file = new File("Type3.jpg");//Type3.jpg放在工程根目录下
InputStream in = new BufferedInputStream(new FileInputStream(file));
System.out.println(file.length());
ps.setBinaryStream(1, in, (int)file.length());

System.out.println(ps.executeUpdate());

ps.close();

conn.close();
}}数据库默认编码为:gbkException in thread "main" com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?;?w?v=??OY?\0?zoü?\'???í?7?~“ò?á@V????\0?Iù???oM?\0?¤ü??P…#}????zoü?\'?' at line 1
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3283)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1332)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1604)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1519)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1504)
at com.hgd.richard.jdbc.MyBlobTest.insert(MyBlobTest.java:34)
at com.hgd.richard.jdbc.MyBlobTest.main(MyBlobTest.java:19)请高手指点