Escaping charaters in insert via JDBC driver

Posted on 2005-04-15
Last Modified: 2012-06-21
PHP have a function called addslashes() that escapes characters such as backslash, single quote and double quote. Are there an equivalent method in Java.

I was told to look at PreparedStatement but the JDBC driver I'm using doesn't implement that method.

The main problem is that sentences are split due to the escape characters.

Does java have an addslashes equivalent or is there any other way of doing this?

Question by:joachimc
    LVL 15

    Accepted Solution

    I don't think Java has special JDBC escape method.
    You can use String.replace or String.replaceAll.
    bsh % "hello\"world".replace("\"","\"\"");
    LVL 4

    Author Comment

    Hmm ok..

    Not exactly what I am hoping for. Anyone else that has heard anything?

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    scoreUp challenge 14 40
    countX 22 50
    allStar challenge 1 27
    word0 challenge 3 31
    An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
    Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
    Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
    Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now