The Artima Developer Community
Sponsored Link

Java Answers Forum
Problem with prepared statement and like operator

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Firmin Dani

Posts: 2
Nickname: firdan
Registered: Jul, 2004

Problem with prepared statement and like operator Posted: Jul 27, 2004 12:04 AM
Reply to this message Reply
Advertisement
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

Topic: Problem with Assertions in java Previous Topic   Next Topic Topic: convert .class to .exe

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use