Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Order list by field with accents using Oracle, NLS & Spring JdbcTemplate

28644Feb 25 2011 — edited Feb 28 2011
I am trying to order a list of Objects by a field that has texts with accents and other 'strange' characters. I am using Spring JdbcTemplate with Oracle 10g.

I have tried modifying the NLS params for the current session, then putting them back the way they were after the select is performed. The reason I have to do it this way is that I don't have access to the configuration of the database, and the client doesn't want be changing these 2 NLS params globally anyway, since I only need them for this one select.

I do something like this:

dao.execute("alter session set NLSCOMP=LINGUISTIC");
_dao.execute("alter session set NLS_SORT=BINARY_AI");

List<MyPojo> pojos = _dao.select(_selectAll);

_dao.execute("alter session set NLS_COMP=LINGUISTIC");
_dao.execute("alter session set NLS_SORT=SPANISH");

The problem is, sometimes it works, sometimes it doesn't. It seems to be random. Sometimes it sorts properly, sometimes it doesn't. Sometimes the accented texts come before, sometimes after.

This would seem to be a problem with either Oracle ... or JdbcTemplate() ... or perhaps C3p0 (connection pool). I read somewhere that for each query a different connection (and as such, session) may be used. Thus setting the NLS params is a waste of time.

My question: what's the best practice for this?

Many thanks!
Bob
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 28 2011
Added on Feb 25 2011
1 comment
1,201 views