473,511 Members | 16,846 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to pass comma separated values in select statement?

7 New Member
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.
May 16 '07 #1
2 8770
sumittyagi
202 Recognized Expert New Member
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.
what is the problem in doing it like this.
String totalDbString = "'ABC', 'DEF', 'GHI'";
String queryString = "SELECT COUNT(DISTINCT(USER_ID)) FROM EDTM_USER_DETAILS WHERE USER_ID IN (" + totalDbString + " )";

Actually ? must be replaced by only one value.
actually what it will be doing internally is (if you do it your way):
"SELECT COUNT(DISTINCT(USER_ID)) FROM EDTM_USER_DETAILS WHERE USER_ID IN ( 'ABC,DEF,GHI' )";
because you have passed a single string, and it puts quotes when you call setString, which is why you are not getting the desired result.
May 16 '07 #2
PraveenAnekalmat
7 New Member
Thanks a lot sumittyagi....It works
May 17 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

7
3068
by: Craig Keightley | last post by:
is it possible to compare acomma separated list aginst another eg comma list 1 => 1,2,3,4,5 comma list 2 => 3,5 can you check that 3 is in both, and 5 is in both, therfore they match??? the...
26
32050
by: Christina | last post by:
I have a post-form that holds a listbox with mulitple selected items. When the form is posted to the server ASP file, I want to loop through the selected items, to insert each of them into a table....
11
2517
by: Craig Keightley | last post by:
I have a mysql database with a list of companies who supply specific products tblSuppliers (simplified) sID | sName | goodsRefs 1 | comp name | 1,2,3,4,5 2 | company 2 | 2,4
12
29052
by: insomniux | last post by:
Hi, I'n in an environment where I cannot make stored procedures. Now I need to make a query with a subquery in the SELECT part which gives a comma separated list of results: SELECT p.id,...
15
5715
by: AK | last post by:
Once upon a time there was a table: CREATE TABLE VENDOR(VENDOR_ID INT, NAME VARCHAR(50), STATE CHAR(2))@ in a while the developers realized that a vendor may be present in xseveral states, so...
11
2361
by: Shawn Odekirk | last post by:
Some code I have inherited contains a macro like the following: #define setState(state, newstate) \ (state >= newstate) ? \ (fprintf(stderr, "Illegal...
9
5291
by: phillip.s.powell | last post by:
Ok, you have three tables. You're supposed to be able to not only sort (ORDER BY) according to a_name, no problem, but you must also have the ability to sort (ORDER BY) the relationship between...
3
6104
by: starman7 | last post by:
I'm attempting a query that gathers product data for a particular product id. One of the items is designer(s) which can be more than one. The product table has comma separated id's of the...
12
4594
by: ArunDhaJ | last post by:
Hi Friends, Is it possible to pass a table as a parameter to a funtion. whos function declaration would look some thing like this.... ALTER FUNCTION TempFunction (@TempTable TABLE, @nPId INT) ...
0
7242
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7138
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7423
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7081
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5668
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3225
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3213
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
781
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
447
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.