我写了个mysql保存文件的例子。。
结果,给我这样一句错误信息: 
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 'cl|??u×??\"a?!?\0??>?TH°>?V?ìF^é????? $?c^fSí  k??é?t\'”??5<4?9B?ü?E6?—W?' at line 1我在保存图片和zip文件的时候会出现这种现象。。怎么会是哦??

解决方案 »

  1.   

    你保存文件的字段用的是什么type啊?
      

  2.   

    我用的是mediumblob ,语句没错误。我直接插入txt,doc类型的文件没错
      

  3.   

    表类型:+----------+------------+------+-----+---------+----------------+
    | Field    | Type       | Null | Key | Default | Extra          |
    +----------+------------+------+-----+---------+----------------+
    | id       | int(11)    | NO   | PRI | NULL    | auto_increment |
    | filedata | mediumblob | NO   |     | NULL    |                |
    | filesize | int(11)    | NO   |     | NULL    |                |
    +----------+------------+------+-----+---------+----------------+
      

  4.   

    特殊字符问题~ 用 preparedStatement 做,然后 setBlob 试试看~
      

  5.   


    额,,我把我的代贴出来算了。
    try {
    Class.forName("org.gjt.mm.mysql.Driver");
    conn = DriverManager
    .getConnection("jdbc:mysql://localhost:3306/mytest?user=root&password=8868829xgj");
    pstat = conn.prepareStatement(sql);
    pstat.setBinaryStream(1, fileItem.getInputStream(), (int) fileItem
    .getSize());
    pstat.setInt(2, (int) fileItem.getSize());
    pstat.executeUpdate();
    } catch (SQLException e) {
    e.printStackTrace();
    flag = "<h3 style='color:red'>SQL错误</h3><br>";
    } catch (IOException e) {
    e.printStackTrace();
    flag = "<h3 style='color:red'>IO错误</h3><br>";
    } catch (ClassNotFoundException e) {
    e.printStackTrace();
    }
      

  6.   

    二进制文件,你怎么能这样在SQL语句里直接insert呢?