java向MYSQL中插入图片时为列属性为LONGBLOB,抛出异常?

yecs0503 2008-07-17 01:30:28
java向MYSQL中插入图片时为列属性为LONGBLOB,抛出异常?大侠们帮帮忙。谢谢了!
代码如下:
public void blobInsert(String infile,int id) throws Exception
{
FileInputStream fis = null;
try
{
fis = new FileInputStream(infile);
String sql = "insert into t_photo values(?,?,?)";
PreparedStatement pstmt = ConnPool.request().getPreStmt(sql);
System.out.println(pstmt.toString());
pstmt.setInt(1, id);
pstmt.setString(2,infile); //把传过来的第二个参数设为文件名
pstmt.setBinaryStream(3,fis,fis.available()); //第三个参数为文件的内容
System.out.println(fis.available());
pstmt.executeUpdate();
}
catch(Exception ex)
{
ex.printStackTrace();
}
finally
{
fis.close();
}
}
...全文
301 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
cuikai314 2012-08-31
  • 打赏
  • 举报
回复
解决了吗 好像是存储过程有问题
mdayday06 2012-05-18
  • 打赏
  • 举报
回复
相同的问题
格物致知1221 2008-09-05
  • 打赏
  • 举报
回复
当然,我数据库的字符集使用的utf-8。
格物致知1221 2008-09-05
  • 打赏
  • 举报
回复
我也碰到了类似的问题,但是情况有所不同,我是在调用存储过程的时候出现了这样的问题,但是直接insert却一切正常,异常的困惑。希望有高人能帮忙。。。
yecs0503 2008-07-17
  • 打赏
  • 举报
回复
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 'mé??d?d?XX?á??i>g4?2?·t?à:”>?§R! Eqhí@?—?+??a\"?{W?@?v??5?¤???j?—?9??Y?' 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:406)
at com.mysql.jdbc.Util.getInstance(Util.java:381)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1031)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:957)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3376)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3308)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1837)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1961)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2543)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1737)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2022)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1940)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1925)
at com.dbpractise.beans.Photo.blobInsert(Photo.java:24)
at com.dbpractise.beans.Photo.main(Photo.java:111)
storyxsj 2008-07-17
  • 打赏
  • 举报
回复
异常信息是什么?

56,940

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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