Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

452
Views
How to insert a string with an apostrophe as the value of the mysql database field with java and j-connector?

I have a database with a "username" field and with Java I insert the values ​​into the database. I tried to enter the username "l'ornitorinco" but the program does not work (crashes). I know that when I insert an apostrophe string with phpMyAdmin like "l'ornitorinco" it is sent in this way "l'ornitorinco". I should probably analyze the string and insert the apostrophe at the appropriate point (with a for loop from 0 to string.length), but does anyone know a more appropriate method? I had read about a method to set the strings for mysql use, but I not remember.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You could use a PreparedStatement, as its setString() method allows you to include apostrophes on the value, making it much simpler than playing the single/doble quote game.

String queryString = "insert into username values (?)";
query = con.prepareStatement(queryString);
query.setString(1, "l'ornitorinco");
query.executeUpdate();

Take a look here for more info. Hope it helps!

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!