0

I am using the webservice that will send the request for one of the column as Dran & Hyle , but i get the exception as a expected valid begining name character. due to the special character &

Below is the insert statement in my java .

    public static final String PetInsert= insert into pet values(?,?,?);

I believe set define off will not work in java code , it is understood only by sql developer.

Any help is appreciated

Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724

2 Answers2

0

From Java, it is recommended to use PreparedStatement when creating a statement to query the database. Read more in the documentation.

aUserHimself
  • 1,589
  • 2
  • 17
  • 26
  • yes thanks for the reply! i have used the prepared statement as PreparedStatement test= connection.prepareStatement(Constants.PetInsert) and i am able to insert the values into the database, but when i try to insert the value into the database for special chracters it throws me such kind of exception, hence i wanted to know how to insert the special characters like '&' into the database – user199702 Sep 27 '13 at 12:32
  • Try to edit the original post and add the full exception stack. Also, specify the database driver you are using. – aUserHimself Sep 27 '13 at 12:34
0

Not so sure, but can it be that in the XML of the web service the error is located? Then somewhere

"Dran & Hyle"

should go into the XML. Normally it is done automatically. So it would be the unlikely case of creating the XML oneself with Strings.

In that case use apache's StringEscapeUtils:

s = StringEscapeUtils.escaleXML(s);

P.S. I found set define off of @aUserHimself plausible.

Joop Eggen
  • 107,315
  • 7
  • 83
  • 138