2

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

3

2 Answers 2

2

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

1
  • is it also same for like statement Sep 29, 2011 at 13:48
1

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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.