Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8705725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:26:12+00:00 2026-06-13T03:26:12+00:00

I am trying to update text into a MySql Database. The text contains marks

  • 0

I am trying to update text into a MySql Database.
The text contains ” marks in it.
As example string could be Hello “world”
now when i write insert command its sumthing like

insert into mytable (‘mystring’) values(“Hello “world””);

I am using java to execute a command like this. Obviously this gives an error due to the double quotes in the world string. I tried replacing it with java
givenString.replaceAll("\"", "\\"");
givenString.replace(Pattern.quote("\""), "\\"");

But nothing works . Any help is greatly appreciated !

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T03:26:13+00:00Added an answer on June 13, 2026 at 3:26 am

    Double escape the \ like so:

    givenString.replaceAll("\"", "\\\"");
    

    As stated by Ted Hopp in comments, for inserting data into a table you should user prepared statements using parameters, and set them according to the API you are using. For example if you are using JDBC you may use the setString method of your Statement object.

    String str = "Hello \"world";
    PreparedStatement stmt = con.prepareStatement(
          "insert into mytable('column') values(?)");
    stmt.setString(1, str);
    

    About your first comment:

    In Java Strings are immutable, so replaceAll returns a new instance whose contents is the string with the required replacements. So what you want is to assign again the result to the previous variable, like so:

    public String getSqlLikeString(String givenString) {
       System.out.println(givenString); 
       givenString = givenString.replaceAll("\"", "\\\""); 
       System.out.println(givenString); 
       return givenString;
    }
    
    // or just
    public String getSqlLikeString(String givenString) {
       return givenString.replaceAll("\"", "\\\"");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to UPDATE a mysql TEXT data-type column with a string contains
I'm making a 'post text' app and trying to update my database with name
So I'm trying to import some sales data into my MySQL database. The data
I am trying to populate a text field with data from a MySQL database,
I am trying update text views while this loop is processing. Here is my
I'm trying to update my text area via ActionScript code using this: scoreLabel.text =
I am trying to update a DateTime object into a datetime field of a
I am trying to update a column in already exists MySQL table. The values
I am trying to make a form using html and php to update mysql
I'm trying to get the rows of my mysql table into Arrays, but I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.