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
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.
try
rs = pstatement.executeQuery();
you have already specified query while creating preparedstatement in
pstatement = connection.prepareStatement(queryString);
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();