Bookmark Topic Watch Topic
  • New Topic

How to use LIKE in prepared statement for Oracle database

 
SANJAY KUMAR
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Report post to moderator
String sql = reportSqlQuery + " WHERE REPORTID LIKE '%?' ";
conn = Connection.getConnection();
ps = conn.prepareStatement(sql);
ps.setInt(1,refreshTime);

rs = ps.executeQuery();
But my sql is not get executing.
Please help me
Am i wrong any where?
-Viku
 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi Viku,
I can only guess what you mean by "my sql is not get executing". I assume you are getting an "SQLException", since your "sql" string seems incorrect. The way you have written it, you are looking for rows (in the database table) where the value of the "REPORTID" column ends in a question-mark ("?"). Is this what you want? Also, the (SQL) "LIKE" operator only works with character data -- so is the "REPORTID" column defined as a CHAR (or VARCHAR)?
If you are getting an "SQLException", perhaps you can post the text and stack trace that is displayed?
Hope this helps you.
Good Luck,
Avi.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Report post to moderator
I didn't realise your two questions are almost the same. I'm going to close this one and direct people who want to help to this thread
Dave
 
    Bookmark Topic Watch Topic
  • New Topic