Problems: insert record with Apostrophe by PreparedStatement
Posted by: Genius Tse
Date: March 06, 2005 10:05AM

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;
}

Options: ReplyQuote


Subject
Written By
Posted
Problems: insert record with Apostrophe by PreparedStatement
March 06, 2005 10:05AM


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.