issue with select IN (?) query

From: "Arun ViswanathanChandrika" <Arun(dot)ViswanathanChandrika(at)ust-global(dot)com>
To: <pgsql-jdbc(at)postgresql(dot)org>
Subject: issue with select IN (?) query
Date: 2008-07-20 13:39:28
Message-ID: 4ADAE57BEACCF2489D5871A8B883F9DD16EE27@TRVMSG.ustr.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Hi

I am facing an issue with following select query

pm = con.prepareStatement("SELECT EMP_NAME FROM EMP where EMP_ID IN (?) ");
pm.setString(1, "2,5,7"); //created many employees and id with 2, 5 and 7
rs = pm.executeQuery(); // query is not returning any values

Is it a bug?

i was using postgresql-8.3-603.jdbc3.jar

==================================================
the code
===================================================

private static void test()
{
Connection con = null;
PreparedStatement pm = null;
ResultSet rs = null;
try
{
String driver = "org.postgresql.Driver";
String dburl="jdbc:postgresql://localhost/test";
Class.forName(driver);
con = DriverManager.getConnection(dburl, "postgres", "postgres");

pm = con.prepareStatement("SELECT EMP_NAME FROM EMP where EMP_ID IN (?) ");
pm.setString(1, "2,5,7"); //created many employees and id with 2, 5 and 7
rs = pm.executeQuery(); // query is not returning any values
if (rs != null && rs.next()) //not returning any values
{
System.out.println(rs.getString(1));
}
else
System.out.println("Nothing...");
}
catch (Exception ex)
{
ex.printStackTrace();
}
finally
{
try {
rs.close();
pm.close();
con.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}

======================================================

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Daniel Migowski 2008-07-22 06:54:49 Re: issue with select IN (?) query
Previous Message Peter 2008-07-20 10:32:51 numeric type