 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Antonio Guest
|
Posted: Fri Jan 16, 2004 4:08 pm Post subject: Prepared statement with ' problem |
|
|
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
|
Posted: Fri Jan 16, 2004 5:21 pm Post subject: Re: Prepared statement with ' problem |
|
|
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
|
|
| Back to top |
|
 |
Scorpio Guest
|
Posted: Fri Jan 16, 2004 9:09 pm Post subject: Re: Prepared statement with ' problem |
|
|
"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 |
|
 |
|
|
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
|
|