java - How to insert a value with single apostrophe in DB2 -


my requirement insert value contains apostrophe,(e.g st.mary's), db2 using java query.

my table has column name datatype char(26) purpose , cannot changed.

i've handled apostrophe using db2 survival guide, way:

string cityname = beanclass.getcity();         if(cityname.contains("'"))         {             cityname.replace("'","''");         }      prepstmt.setstring(1, cityname); 

query looks like:

insert tablename(cityname) values(?); (where values being received preparedstatement(index,string) (prepstmt.setstring(int,string)) 

please me insert value "st.mary's" apostrophe db2.

thanks loads, varsha.

the escape character single quote double single quote. example, insert st.mary's need do

 insert table values ('st.mary''s') 

however, plain sql. depends how call java. if column parameter marker in prepared statement, not need that.

also, if pass parameter other components, need escape single quote character.


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -