Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Problem Prepared Statement with like operator

843854Jul 27 2004 — edited Jul 27 2004
Hi,

I am having a problem when i use prepared statement with like operator query.
if i give a select statement with where clause it works fine but it does fetch any rows if i give a like statement with parameters.

The method takes a query as String and its parameter are arraylist and returns the resultset.

public ResultSet executeQuery(String psquery,ArrayList poparams) throws Exception
{
ResultSet mors = null;
PreparedStatement mops = null;
try
{
mops=con.prepareStatement(psquery);
if(poparams != null)
{
for(int i=0;i<poparams.size();i++)
{
Object value = poparams.get(i);
if(value != null)
{
Object obj = value.getClass();
if(obj.toString().equals("class java.lang.Integer"))
{
mops.setInt(i+1,((Integer)poparams.get(i)).intValue());
}
else
{
mops.setString(i+1,(String)poparams.get(i));
}
}
}
}
mors = mops.executeQuery();
}
catch(Exception e)
{
e.printStackTrace();
}
return mors;
}

For eg:
Query: Select * from emp where empname = ?
poparams : new arraylist().add("dani")
Return resultset

Query: Select * from emp where empname like ?
poparams : new arraylist().add("dani")
Returns empty resultset

Any suggestion would be of much help
Thanx in advance.
regards,
Firmin Dani
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 24 2004
Added on Jul 27 2004
4 comments
163 views