It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Partner Sites
Board index Programming Java Forum

How to pass comma separated values in select statement

How to pass comma separated values in select statement

Postby PraveenAnekalmat on Wed May 16, 2007 6:20 am

Hi everyone,


String totalDbString = "ABC,DEF,GHI";
String queryString = "SELECT COUNT(DISTINCT(USER_ID)) FROM EDTM_USER_DETAILS WHERE USER_ID IN ( ? )";
PreparedStatement ps = oracon.prepareStatement( queryString );
ps.setString(1, totalDbString);
ResultSet rs = null;
rs = ps.executeQuery();
while (rs.next()) {
id = rs.getInt(1);
}

The count is coming 0 even it is greater than 0.
I need to perform this,
SELECT COUNT(DISTINCT(USER_ID)) FROM EDTM_USER_DETAILS WHERE USER_ID IN ( 'ABC','DEF','GHI')";
And above statement works fine with giving count greater than 0 .

How can i pass 'ABC','DEF','GHI' in ? as parameter. Please Help.
:?:
PraveenAnekalmat
 
Posts: 4
Joined: Fri May 04, 2007 10:51 am

Re:how can I pass the comma separated values in the select

Postby manojdeoli on Tue Jun 19, 2007 1:29 pm

I think when we use the setString() method, it'll put the quotes in the String you are passing in the query. e.g.
String totalDbString = "ABC,DEF,GHI";

It'll pass like 'ABC,DEF,GHI' , and will not give the expected result.

So we can use:
"SELECT COUNT(DISTINCT(USER_ID)) FROM EDTM_USER_DETAILS
WHERE USER_ID IN ( "+ totalDbString +")";
manojdeoli
 
Posts: 0
Joined: Tue Jun 19, 2007 11:50 am

Postby nksol on Tue Mar 18, 2008 10:20 am

I think using string tokenizer, we can do easly.
devide the string with cama delimeter and add to sql statement
Thank you
nksol
 
Posts: 0
Joined: Tue Mar 18, 2008 9:41 am


Return to Java Forum

Who is online

Users browsing this forum: No registered users and 0 guests