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(); 


解决方案 »

  1.   

    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)
      

  2.   

    我也碰到了类似的问题,但是情况有所不同,我是在调用存储过程的时候出现了这样的问题,但是直接insert却一切正常,异常的困惑。希望有高人能帮忙
      

  3.   

    当然,我数据库的字符集使用的utf-8。