AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Prepared statement with ' problem

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java and Databases
View previous topic :: View next topic  
Author Message
Antonio
Guest





PostPosted: Fri Jan 16, 2004 4:08 pm    Post subject: Prepared statement with ' problem Reply with quote



Good Morning,
I've this prepared statement

PreparedStatement pstm =
" select domicilio from anagrafe where id_struttura IN (?) "
pstm.setString(1, " '60' , '12' , '85' , '45' ");


it seems that the ' in the string inserted like a parameter is a problem
how can I solve this ?? I've a variable number of values inside the IN.

Thanks

Antonio D'Ottavio
Back to top
Joe Weinstein
Guest





PostPosted: Fri Jan 16, 2004 5:21 pm    Post subject: Re: Prepared statement with ' problem Reply with quote





Antonio wrote:

Quote:
Good Morning,
I've this prepared statement

PreparedStatement pstm =
" select domicilio from anagrafe where id_struttura IN (?) "
pstm.setString(1, " '60' , '12' , '85' , '45' ");


it seems that the ' in the string inserted like a parameter is a problem
how can I solve this ?? I've a variable number of values inside the IN.

Thanks
Parameter setting is only for single specific data values, not for subsections of SQL.

You could count the number of values before preparing the statement, or you could
not use a prepared statement:

Statement s = c.createStatement();
ResultSet r = s.executeQuery(" select domicilio from anagrafe where id_struttura IN ("
+ " '60' , '12' , '85' , '45' "
+ ")" );
Joe Weinstein at BEA
Quote:

Antonio D'Ottavio


Back to top
Scorpio
Guest





PostPosted: Fri Jan 16, 2004 9:09 pm    Post subject: Re: Prepared statement with ' problem Reply with quote




"Antonio" <etantonio (AT) libero (DOT) it> ha scritto nel messaggio
news:bad37d99.0401160808.67348c88 (AT) posting (DOT) google.com...
Quote:
Good Morning,
I've this prepared statement

PreparedStatement pstm =
" select domicilio from anagrafe where id_struttura IN (?) "
pstm.setString(1, " '60' , '12' , '85' , '45' ");

You're passing a string (i.e, a Varchar /CHAR parameter from dbms point of
view), while it's expecting an enumeration of values.

Quote:
it seems that the ' in the string inserted like a parameter is a problem
how can I solve this ?? I've a variable number of values inside the IN.

Try with :

Statement st = connection.createStatement();
String sql = " select domicilio from anagrafe where id_struttura IN "
String restriction = " ( '60' , '12' , '85' , '45' ) ";
sql += restriction;
ResultSet rs = st.executeQuery(sql);

Hope it helps.

Scorpio.





Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java and Databases All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.