Thread: issue with select IN (?) query
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();
}
}
}
======================================================
Hello Arun,<br /><br /> Arun ViswanathanChandrika schrieb: <blockquote cite="mid:4ADAE57BEACCF2489D5871A8B883F9DD16EE27@TRVMSG.ustr.com"type="cite"><p><font size="2"><br /><br /> pm =con.prepareStatement("SELECT EMP_NAME FROM EMP where EMP_ID IN (?) ");<br /> pm.setString(1, "2,5,7"); //createdmany employees and id with 2, 5 and 7<br /></font></blockquote> Resolves to: <font size="2">SELECT EMP_NAME FROMEMP where EMP_ID IN ('2,5,7');<br /><br /> Watch the "'"'s :)<br /><br /> With best regards,<br /> Daniel Migowski</font>