求大神指教下面的代码到底哪里出错了,执行到 pstmt.execute()为什么总是会报错???
  
  
  <%@ page contentType="text/html;charset=gb2312" %>
   <%@ page import="java.sql.*" %>
   <%@ page import="java.util.*" %>
   <%@ page import="java.text.*"%>
   <%@ page import="java.io.*" %>
   
   
   
   <html>
   <head>
   <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
   <title>save picture</title>
   </head>
   <body>
   <%
         String DBDRIVER ="org.gjt.mm.mysql.Driver";
      String DBURL ="jdbc:mysql://localhost:3306/picture";
      String DBUSER ="root";
      String DBPASS="999";//数据库密码
      
         Class.forName(DBDRIVER).newInstance();
         Connection conn=DriverManager.getConnection(DBURL,DBUSER , DBPASS);
        String ID=request.getParameter("ID");//接受图片编号
        String filename=request.getParameter("image");//接收图片URL
        FileInputStream str = new FileInputStream(filename);
        String sql = "insert into picture (ID,Pic) values(?,?)";
   
        PreparedStatement pstmt = conn.prepareStatement(sql);
        pstmt.setString(1,ID);
        pstmt.setBinaryStream(2,str,(int)str.available());
       
        try{
           pstmt.execute();
          
        out.println("恭喜,已添加成功");
        }catch(Exception e)
        {
          out.println("出错!!!!");
        }
               
   %>
   </body>
   </html>
   
   

解决方案 »

  1.   

    打印出来你的sql直接去数据库里执行看看成功不成功
      

  2.   

    字段什么类型,提示什么,MYSQL、MYSQLODBC什么版本
    插入图片到MySQL的代码如下:  
    String sql = "insert into insertblob set pic = ?"
       PreparedStatement ps = this.conn.prepareStatement(sql);
       FileInputStream fin = new FileInputStream(new File(filename));
       ps.setBinaryStream(1,fin,fin.available());
       ps.execute();
      

  3.   

    我那样改为什么报错呢,com.mysql.jdbc.exceptions.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 '?úê,òn”í@s÷s_MV?d?\"±\'??Q?í??/Q???w?????I·???q±???Mó???K?E ?ù
     您写的代码里的 File(filename)里的filename是图片的url?我怎么得到一个正确的url?