Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将PDF文件更新为mysql BLOB您的SQL语法有错误;_Java_Mysql_Sql - Fatal编程技术网

Java 将PDF文件更新为mysql BLOB您的SQL语法有错误;

Java 将PDF文件更新为mysql BLOB您的SQL语法有错误;,java,mysql,sql,Java,Mysql,Sql,我上传了一个PDF文件到MySQL数据库,但更新方法不起作用。它一直在运行。如果给我一个错误,我试图修复它,但无法工作 这就是方法 public void updateProjet(String location,String img) throws Exception { // Créer une connexion JDBC Oracle sur la Base de Données .. ici connec

我上传了一个PDF文件到MySQL数据库,但更新方法不起作用。它一直在运行。如果给我一个错误,我试图修复它,但无法工作 这就是方法

public void updateProjet(String location,String img) throws Exception
              {
                   // Créer une connexion JDBC Oracle sur la Base de Données 
       .. ici connection ..

           String cad = "update  projet set NomProjet='"+this.getnom_projet()+
             "', DateDeb='"+this.getdd()+ "', DateFin='"+this.getdf()+
             "', iduser='"+this.getid()+ "',IdProjet='"+this.getnprojet()+
           "',?,? where idpro='"+this.getidpro()+"'";
        PreparedStatement pStmt = conn.prepareStatement(cad);
        pStmt.setString(1, img);

        File fichier = new File(location);
        FileInputStream io = new FileInputStream(fichier);
        pStmt.setBinaryStream(2,  (InputStream)io,(int)fichier.length());

        pStmt.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 ''Exercices2_corrige_2.pdf',_binary'%PDF-1.4
%Çì�¢
5 0 obj
<</Length 6 0 R/Filter' at line 1
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:您的SQL语法有错误;请查看与MySQL服务器版本对应的手册,以了解在“exercies2\u corrige\u 2.pdf”附近使用的正确语法,以及二进制文件“%pdf-1.4”
%Çì�¢
50 obj

似乎没有为语句的参数化值设置列名。 您必须使用以下内容:
columnName=?
您单独使用
的位置


正如评论中所指出的,在所有参数请求中使用参数化参数是一种更好的做法,以防止SQL注入漏洞。

您有一个。现在修复它,在有人为你破坏你的服务器之前。那很好,我忘记了名字,6个小时的工作,我不能继续了,谢谢。但是使用参数化语句确实很重要。看一看:但是基本上使用
,就像你对两个参数所做的那样,而不是添加字符串来创建查询。这很简单,它只是用来做查询的?每次都是这样,这是否修复了sql注入?