single quotes again - Mailing list pgsql-jdbc

From tony
Subject single quotes again
Date
Msg-id 1018082784.4094.7.camel@annix
Whole thread Raw
Responses Re: single quotes again  (tony <tony@animaproductions.com>)
List pgsql-jdbc
Hello,

In looking around for a way to insert entries via html for via JDBC
containing single quotes I came upon this:

escapeQuotes

protected java.lang.String escapeQuotes(java.lang.String old)

Tokenizes the original string with \' and \" as delimiters, then
replaces them with \\\' and \\\", respectively. This is primarily useful
for escaping quotes that will be interpreted as part of a mySQL query.

Is there a method like this that is callable for Postgresql  JDBC driver
too?

I also found this method

private String escape(String s) {
    String retvalue = s;
    if ( s.indexOf ("'") != -1 ) {
    StringBuffer hold = new StringBuffer();
    char c;
    for ( int i = 0; i < s.length(); i++ ) {
        if ( (c=s.charAt(i)) == '\'' )
        hold.append ("''");
        else
        hold.append(c);
    }
    retvalue = hold.toString();
    }
    return retvalue;
}

Not being a java god - where do I insert this in my jsp code? Each form
has several fields where single quotes may be inserted.

TIA

Cheers

Tony Grant


--


pgsql-jdbc by date:

Previous
From: Dave Cramer
Date:
Subject: Re: Syntax of LIKE in PreparedStatement
Next
From: tony
Date:
Subject: Re: single quotes again