解决下这个JDBC问题
源代码“import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.DriverManager;
import java.sql.SQLException;
import
import
import
public class BlobDemo1{
private static final String Driver="org.gjt.mm.mysql.Driver";
private static final String dburl="jdbc:mysql://localhost:3306/justhin";
private static final String user="root";
private static final String password="admin";
public static void main(String args[]) throws Exception{
Connection con=null;
PreparedStatement psmt=null;
// ResultSet rs=null;
String name="平南";
String sql="insert into blob1(name,movies) values(?,?)";
Class.forName(Driver);
con=DriverManager.getConnection(dburl,user,password);
psmt=con.prepareStatement(sql);
File f=new File("F:"+File.separator+"20110821482.jpg");
InputStream input=null;
input=new FileInputStream(f);
psmt.setString(1,name);
psmt.setBinaryStream(2,input,(int)f.length());
psmt.executeUpdate();
input.close();
psmt.close();
con.close();
}
}运行报错:
Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorExce
tion: You have an error in your SQL syntax; check the manual that corresponds t
your MySQL server version for the right syntax to use near 'd?e?\"#U?)laj°?
I%?è????íòJ?íe??L??9?\0??hkà@}?7/???\' {??M?2LkO??÷?D?à??' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown So
rce)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.Util.getInstance(Util.java:381)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1030)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2542)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.j
va:1734)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.jav
:2019)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.jav
:1937)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.jav
:1922)
at BlobDemo1.main(BlobDemo1.java:30)
数据库:
mysql> desc blob1;
+--------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(30) | NO | | | |
| movies | longblob | YES | | NULL | |
+--------+-------------+------+-----+---------+----------------+