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

Dave Newton
  • 158,873
  • 26
  • 254
  • 302
agarwal_achhnera
  • 2,582
  • 9
  • 55
  • 84

2 Answers2

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

rkmax
  • 17,633
  • 23
  • 91
  • 176
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?

Community
  • 1
  • 1
James Jithin
  • 10,183
  • 5
  • 36
  • 51