single quotes again

From: tony <tony(at)animaproductions(dot)com>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: single quotes again
Date: 2002-04-06 08:46:24
Message-ID: 1018082784.4094.7.camel@annix
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

--

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message tony 2002-04-06 09:08:57 Re: single quotes again
Previous Message Mihai Gheorghiu 2002-04-05 21:49:24 Syntax of LIKE in PreparedStatement