The method executeQuery() cannot take arguments on a PreparedStatement or CallableStatement. Error

后端 未结 3 1777
夕颜
夕颜 2021-01-12 02:32

I am having this kind of error when trying to connect and retrieve data from my database.

The method executeQuery() cannot take arguments on a PreparedStatement or C

相关标签:
3条回答
  • 2021-01-12 03:22

    Just add { } for your querystring.i.e

    String queryString = "{SELECT P_ID, lname, fname, mname FROM stu_info Where lname = ?}";
    

    execute() and executeUpdate() will both work. executeQuery() only works when your procedure returns a result set.

    0 讨论(0)
  • 2021-01-12 03:26

    try

     rs = pstatement.executeQuery();
    

    you have already specified query while creating preparedstatement in

     pstatement = connection.prepareStatement(queryString);
    
    0 讨论(0)
  • 2021-01-12 03:31

    you don't need the queryString the second time, because you "told" the preparedStatement the String with this:

    pstatement = connection.prepareStatement(queryString);
    

    this would be the right way:

     pstatement = connection.prepareStatement(queryString);
     pstatement.setString(1, search);
     rs = pstatement.executeQuery();
    
    0 讨论(0)
提交回复
热议问题