向mysql中插入数据报错

yao428650 2011-11-27 10:59:05
在向mysql中插入blob格式的图片时会报错的,而且报错的原因出现乱码,找了半天不知何故啊!

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)
...全文
291 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
Davidtsang 2011-11-27
  • 打赏
  • 举报
回复
你安装的mysql是设置成什么语言的?是GB2312还是其它?
hllfl 2011-11-27
  • 打赏
  • 举报
回复
sql语法错误

23,407

社区成员

发帖
与我相关
我的任务
社区描述
Java 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧