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
Post a Comment