Re: Problems: insert record with Apostrophe by PreparedStatement
Posted by: Mark Matthews
Date: March 06, 2005 04:36PM

Genius Tse wrote:
> I m using JSP + JavaBeans to access Mysql with
> PreparedStatement
> when insert a records which contains Apostrophe
> and the SQLException will be thrown
>
> According exception message, it shows that the SQL
> statement is added \\ in front of all Apostrophe
> input: 123'456'789
> error msg in console: 123\\'456\\'789
>
> Does anybody can help me ~~~
>
> and the following is a parts of the source code:
> ------------------------------------------------
> public int insertLinkCat(LinkCat linkcat){
> int insertCount=0;
> try{
> sql="insert into link_catalog(catID,
> cat_name) values(?,?)";
> Connection conn=db.getConnection();
> PreparedStatement
> pstm=conn.prepareStatement(sql);
> int i=1;
>
> pstm.setInt(i++,linkcat.getCatID());
>
> pstm.setString(i++,linkcat.getCatName());
>
> insertCount=pstm.executeUpdate();
>
> conn.close();
> }
> catch(SQLException sql){
> sql.printStackTrace();
> }
> return insertCount;
> }


What character set is your database set to? What version of MySQL are you using? The driver _should_ be sending '\' before single quotes, as it's required...If you're saying it's sending '\\' instead, then it's probably a bug, but related to the character set you're using.

-Mark

Mark Matthews
Consulting Member Technical Staff - MySQL Enterprise Tools
Oracle
http://www.mysql.com/products/enterprise/monitor.html

Options: ReplyQuote


Subject
Written By
Posted
Re: Problems: insert record with Apostrophe by PreparedStatement
March 06, 2005 04:36PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.