From: Kris Jurka <books@ejurka.com>
To: Andrew Lindesay <apl@lindesay.co.nz>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: LIKE and ESCAPING in JDBC Select Statement
Date: Fri, 29 Jan 2010 16:17:25 -0500 (EST)
Message-ID: <alpine.BSO.2.00.1001291616340.31378@leary.csoft.net> (raw)
In-Reply-To: <EBA5F58E-BE84-4AB0-AB8B-72167B21295E@lindesay.co.nz>
References: <EBA5F58E-BE84-4AB0-AB8B-72167B21295E@lindesay.co.nz>
On Sat, 30 Jan 2010, Andrew Lindesay wrote:
> I am trying to use the JDBC LIKE escape clause with PG 8.4 and the PG
> 8.4 JDBC driver.
>
> So far I have tried;
>
> SELECT ... WHERE ... AND (t0.MESSAGE ILIKE ? {escape '|'}) LIMIT 50
This works for me as attached. Please be more clear what your problem is.
Kris Jurka
Attachments:Escape.java (text/plain, 533B) download
import java.sql.*;
public class Escape {
public static void main(String args[]) throws Exception {
Class.forName("org.postgresql.Driver");
Connection conn = DriverManager.getConnection("jdbc:postgresql://localhost:5432/jurka", "jurka", "");
PreparedStatement pstmt = conn.prepareStatement("SELECT 'a' ILIKE ? {escape '|'}");
pstmt.setString(1, "|_");
ResultSet rs = pstmt.executeQuery();
rs.next();
System.out.println(rs.getBoolean(1));
rs.close();
pstmt.close();
conn.close();
}
}
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: books@ejurka.com, apl@lindesay.co.nz
Subject: Re: LIKE and ESCAPING in JDBC Select Statement
In-Reply-To: <alpine.BSO.2.00.1001291616340.31378@leary.csoft.net>
References: <EBA5F58E-BE84-4AB0-AB8B-72167B21295E@lindesay.co.nz> <alpine.BSO.2.00.1001291616340.31378@leary.csoft.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox