Select in Mysql by skipping simple quotes

Asked

Viewed 555 times

0

Hello How can I use this select and skip value with simple quotation mark?

.
.
.st.executeQuery("select * from tabela_A where id = uc");

        rs = st.getResultSet();


        while (rs.next()) {

                texto = rs.getString("rua")
           }...

...the problem is that when the street is for example Passo'Dareia, I want to eliminate this simple quote, because otherwise I will have an error in the sequence of the system...

ps. the select is being done in MYSQL, and the return(rs.getString) used in a JSP page.

  • What error for example? You want to delete in the return or it can be later, within the same text variable?

2 answers

1


You can treat the return right away in the result.

texto = rs.getString("rua");
if (null != texto) {
  texto = texto.replaceAll("\'","");
}
  • So that the counter?

  • Backslash serves to escape the character and be accepted as it is being used. It would not work without it.

  • replaceAll takes a regular expression (Regex), so you need to escape the single quote.

  • @ricktg But it is not better to use texto.replace("'", "")? What would be the justification for using regular expression?

  • It is neither better nor worse because the two methods use Pattern and Matcher to perform the search. In my opinion the regex is more assertive in the char search.

  • Thank you very much! That’s right....

Show 1 more comment

0

Browser other questions tagged

You are not signed in. Login or sign up in order to post.