From: | Anton Moiseev <benderamp(at)gmail(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | citext data type does not work with JDBC PreparedStatement? |
Date: | 2011-08-06 09:28:08 |
Message-ID: | CAJFs0QB90bo0vWw5pZcw0c=LjOcOX04qPEM4nSd6uY7-T2r5hA@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hi,
I wanted to have case-insensitive user names in my db and found that citext
postgresql data type (
http://www.postgresql.org/docs/8.4/interactive/citext.html) is exactly what
I need.
So I have added to my db and it seemed to work fine when query db from
command line interface, but when I run it from java prepared statement,
things do not work as expected.
For example, I have user name 'Leon' stored in the db and want to get
password for him.
If I execute query in sql console:
SELECT password FROM users WHERE name = 'leon';
it returns password ok.
But if I do the query from java in this way:
final String query = "SELECT password FROM users WHERE name = ?";
final PreparedStatement stmt = dbConnection.prepareStatement(query);
stmt.setString(1, "leon");
final ResultSet resultSet = stmt.executeQuery();
if(resultSet.next()) {
System.out.println("password is:" + resultSet.getString(1));
} else {
System.out.println("password not found");
}
password won't be found. If I change parameter substitution like that:
final String query = "SELECT password FROM users WHERE name =
'leon'";
final PreparedStatement stmt = dbConnection.prepareStatement(query);
final ResultSet resultSet = stmt.executeQuery();
if(resultSet.next()) {
System.out.println("password is:" + resultSet.getString(1));
} else {
System.out.println("password not found");
}
the password would be again returned.
Any ideas why this can happen and how to fix this?
thank's
Anton
From | Date | Subject | |
---|---|---|---|
Next Message | Fernando Pianegiani | 2011-08-06 09:48:44 | Re: FREE hosting platforms with PostgreSQL, Java SDK, Tomcat, ecc.? |
Previous Message | Allan Kamau | 2011-08-06 08:36:32 | Re: FREE hosting platforms with PostgreSQL, Java SDK, Tomcat, ecc.? |