Firmin Dani
Posts: 2
Nickname: firdan
Registered: Jul, 2004
Problem with prepared statement and like operator
Posted: Jul 27, 2004 12:04 AM
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