Try toFind the Problem in the Query...

Discussions

EJB programming & troubleshooting: Try toFind the Problem in the Query...

  1. Hi ,
    Here is the code is used to retrive from the db with using the IN operator but i am getting no of the record but the same query works in the oracle if I ran this below query...

    Connection con = ts.getConnection();
    PreparedStatement ps = con.prepareStatement("Select column_name from table_name where Column_Name in( ? ) ");
    System.out.println(Helper.getSysdate());
    ps.setString(1,"'DATA1','DATA2'");
    ResultSet rs = ps.executeQuery();
    I have tried with several posiblities with the Preparedst with binding the valus ...
    but the same query works if i give
    ("Select column_name from table_name where Column_Name in( "'DATA1','DATA2'") ");

    can any one tell me why the above code is not working
    Thanks for ur reply in advance.........


  2. Prepared Statement puts quotes for any setString .
    So when you say
    ps.setString(1,"'DATA1','DATA2'");
    the value set is
    ''DATA1','DATA2''

    this means ques\ry searches for the whole string
    hence no record found .

    hope this helps...
    mohan
  3. Thanks for ur reply ,Let me check out...