Re: Updating a chkpass column in postgres v8.1.21

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Nelson, Howard C" <howard(dot)c(dot)nelson(at)lmco(dot)com>
Cc: "pgsql-novice(at)postgresql(dot)org" <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Updating a chkpass column in postgres v8.1.21
Date: 2012-05-17 18:44:37
Message-ID: 29560.1337280277@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-novice

"Nelson, Howard C" <howard(dot)c(dot)nelson(at)lmco(dot)com> writes:
> I am using the JDBC prepareStatement object to build a SQL statement that should update a users password in a postgres v8.1.21 database. (Based on what I have read, chkpass became a "contrib module" starting at 8.3, but I have to use an older version of postgres.) Here is my java code/snippet:

No, it's been in contrib a long time...

> // Build an SQL statement with caller's parameters
> private static final String m_defaultPass = "changeme";
> stmtStr = "UPDATE users SET pwd_date=now(), pwd=? " + "WHERE user_id=?;";
> stmt = con.prepareStatement(stmtStr);
> stmt.setString(1, m_defaultPass);
> stmt.setString(2, userId);

This is telling JDBC that parameter 1 is a string (hence, character
varying); but there is no cast from varchar to chkpass (hence, fail).

It might work to use setObject not setString there, but not sure because
I'm not a Java person. You might get more help on that from the
pgsql-jdbc list.

In more recent PG versions you could definitely fix it with an explicit
cast in the query, ie "SET pwd=?::chkpass", but I think that will not
work in 8.1.

BTW, 8.1 has been out of support for awhile. You really need to think
about upgrading.

regards, tom lane

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Nart Tamash 2012-05-18 10:47:10 SELECT FROM 'varying_table'
Previous Message Nelson, Howard C 2012-05-17 17:44:48 Updating a chkpass column in postgres v8.1.21