Selecting on non ASCII varchars

From: Jeremy LaCivita <jlacivita(at)broadrelay(dot)com>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Selecting on non ASCII varchars
Date: 2005-10-02 06:22:45
Message-ID: 19B7E72C-CA44-42AE-803E-E87421EC30F9@broadrelay.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Hi,

I have a unicode database. Inserting unicode strings works fine.
Selecting data based on int columns works fine too.

However, I am unable to select based on varchar columns when the
select contains non ascii characters.

the same select will work in Aqua Data Studio, just not from java.
Am i setting up my connections or prepared statements wrong?

/* begin example code */
javax.naming.InitialContext ctx = new javax.naming.InitialContext();
javax.sql.DataSource ref1 = (javax.sql.DataSource)ctx.lookup("java:/
PostgresDS");
Connection conn = ref1.getConnection();
PreparedStatement pst = conn.prepareStatement("SELECT * from mytable
m where m.title ~* ?");
pst.setString(1, myString);
ResultSet rs = pst.executeQuery();
/* end example code */

mytable.title is a varchar(300)
myString is a java.lang.String which was loaded from a unicode xml
stream.

whenever myString contains accented or chinese characters, for
example, the result set will be empty even though there are records
in the database that should match. doing the same query manually in
aqua data studio works fine.

I'm using postgres 8.0.3

Any ideas?

-Jeremy

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Oliver Jowett 2005-10-03 01:41:09 Re: Selecting on non ASCII varchars
Previous Message Russell Francis 2005-10-01 17:39:32 Re: queries against CIDR fail against 8.0.3?