日期:2014-05-20  浏览次数:20691 次

向mysql中插入数据报错
在向mysql中插入blob格式的图片时会报错的,而且报错的原因出现乱码,找了半天不知何故啊!
Java code

    String sql = "insert into userseal (Id,SealName,SealPic,date) values(1,'fuck',?,'2011-11-21 00:33:33')";
            ps = conn.prepareStatement(sql);
            File file = new File("D:\\darren_seal.png");
            fis = new FileInputStream(file);
            ps.setBinaryStream(1, fis,fis.available());
            ps.executeUpdate();




com.mysql.jdbc.exceptions.jdbc4.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 'ç?“?S_æ??+\0ï¹?J0飿Jé??Hé ?&?è?…u?è¾±æ?‰9@?è??zä¹—0ç±?è?¯?è???é®?M?&é­¬倧' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1052)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3609)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3541)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2002)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2163)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2624)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2127)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2427)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2345)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2330)
at local.DBTest.main(DBTest.java:25)


------解决方案--------------------
sql语法错误