String query = "SELECT * FROM professores WHERE nome Like '?';";
PreparedStatement ps = getConnection().prepareStatement(query);
ps.setString(1, nomeProf);
error I'm getting: UCAExc:::4.0.2 Invalid argument in JDBC call: parameter index out of range: 1
please, help.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Parameter placeholders are simply bare question marks. They should never be enclosed in quotes, hash marks, or any other delimiter. '?' is not a parameter placeholder, it is a literal string containing a single question mark. To use a parameterized LIKE query you should do something similar to this:
Stringquery="SELECT * FROM professores WHERE nome Like ?";PreparedStatementps=getConnection().prepareStatement(query);ps.setString(1,nomeProf+"%");
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks man, that worked.
I was trying with the quote because the sintaxe for the MS Access use the quote, did'nt realize it wold work with the '%'.
Did'nt realize I should put the '%' inside the ps.setString()
summarizing for people with similar problem:
I was trying :
Stringquery="SELECT * FROM professores WHERE nome Like %?%";PreparedStatementps=getConnection().prepareStatement(query);ps.setString(1,nomeProf);
It work like:
Stringquery="SELECT * FROM professores WHERE nome Like ?";PreparedStatementps=getConnection().prepareStatement(query);ps.setString(1,"%"+nomeProf+"%");
Sorry for the bad english.
Thank you.
Last edit: Hugo P. 2017-09-09
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello.
I'm tring to make this work, but unable to do so.
String query = "SELECT * FROM professores WHERE nome Like '?';";
PreparedStatement ps = getConnection().prepareStatement(query);
ps.setString(1, nomeProf);
error I'm getting: UCAExc:::4.0.2 Invalid argument in JDBC call: parameter index out of range: 1
please, help.
Parameter placeholders are simply bare question marks. They should never be enclosed in quotes, hash marks, or any other delimiter.
'?'
is not a parameter placeholder, it is a literal string containing a single question mark. To use a parameterized LIKE query you should do something similar to this:Thanks man, that worked.
I was trying with the quote because the sintaxe for the MS Access use the quote, did'nt realize it wold work with the '%'.
Did'nt realize I should put the '%' inside the ps.setString()
summarizing for people with similar problem:
I was trying :
It work like:
Sorry for the bad english.
Thank you.
Last edit: Hugo P. 2017-09-09