agarwal_achhnera
agarwal_achhnera

Reputation: 2456

how to set placeholders in like statement query

I am creating a PreparedStatement with SQL which have a like statement, and I am setting the placeholders using setString(), method, but it does not give any error or fetch any records. When I run the query direct at database by setting arguments in like statements then I get results, so I think there may be any other way to put place holders in sql, I am doing like below:

select name from employee where name like ?

I also tried:

select name from employee where name like (?)

and set parameters using setString() method but I did not get any results.

Please help what is wrong in it

Upvotes: 2

Views: 7053

Answers (2)

James Jithin
James Jithin

Reputation: 10565

It is the way by which you used it first. If you need another post which explains this, please see:

Cannot use a LIKE query in a JDBC PreparedStatement?

Upvotes: 1

rkmax
rkmax

Reputation: 18125

this is an example from API:

PreparedStatement pstmt = con.prepareStatement("UPDATE EMPLOYEES
                                     SET SALARY = ? WHERE ID = ?");
   // set the first (?)
   pstmt.setBigDecimal(1, 153833.00)
   // set the second (?)
   pstmt.setInt(2, 110592)

you can see more in : http://download.oracle.com/javase/1.4.2/docs/api/java/sql/PreparedStatement.html

Upvotes: 2

Related Questions