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 无法解决没有为参数1指定值的问题_Java_Mysql - Fatal编程技术网

Java 无法解决没有为参数1指定值的问题

Java 无法解决没有为参数1指定值的问题,java,mysql,Java,Mysql,您好,我正在尝试运行此代码,但我遇到了此问题,我不知道问题出在哪里。如果有人能提供帮助,我将不胜感激 这是密码 public List<String> AfficherParXp(String xpath) { List<String> lp = new ArrayList<>(); try { String requete="select function_name from functions where X

您好,我正在尝试运行此代码,但我遇到了此问题,我不知道问题出在哪里。如果有人能提供帮助,我将不胜感激 这是密码

public List<String> AfficherParXp(String xpath) {
    List<String> lp = new ArrayList<>();
   try {
    
       String requete="select function_name from functions where Xpath= ?";
      
       pste = con.prepareStatement(requete);
       pste.setString(1,xpath);
      rs = pste.executeQuery();

     while(rs.next()) {
        
     lp.add(rs.getString("function_name"));
     } 
     
   } catch (SQLException ex) {
       Logger.getLogger(LoginwithInvalidIdTest.class.getName()).log(null, ex);
   }
    return lp;
}

您正试图将参数值添加到
PreparedStatement
,但您的查询
字符串
不包含占位符(
)。相反,您连接了
xpath
变量(这意味着不需要添加参数和易于SQL注入的语句/查询(理论上)**。请为参数使用占位符,如
String requete=“select function\u name from functions where xpath=?”
感谢您的回复,我已经用占位符(?)替换了它,但仍然收到相同的错误。您的代码现在看起来如何?String requete=“select function_name from functions where Xpath=?”;pste=con.preparest陈述(requete);pste.setString(1,Xpath);rs=pste.executeQuery();您试图将参数值添加到
PreparedStatement
,但您的查询
String
不包含占位符(
)。相反,您将
xpath
变量连接在一起(这意味着无需添加参数和易于SQL注入的语句/查询(理论上)**。对参数使用占位符,例如
String requete=“从Xpath=”的函数中选择函数名称“
谢谢您的回复,我已经用占位符(?)替换了它,但仍然会遇到相同的错误。您的代码现在看起来如何?String requete=“从Xpath=”的函数中选择函数名称”;pste=con.prepareStatement(requete);pste.setString(1,xpath);rs=pste.executeQuery();
java.sql.SQLException: No value specified for parameter 1
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:965)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:898)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:887)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:861)
    at com.mysql.jdbc.PreparedStatement.checkAllParametersSet(PreparedStatement.java:2256)
    at com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:2236)
    at com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:2166)
    at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1986)
    at test.java.Login.Suite.LoginwithInvalidIdTest.getAllFunctionsOfXpath(LoginwithInvalidIdTest.java:243)
    at test.java.Login.Suite.LoginwithInvalidIdTest.Test_LoginwithInvalidId(LoginwithInvalidIdTest.java:114)