pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feedSwitching user within connection.
6+ messages / 2 participants
[nested] [flat]
* Switching user within connection.
@ 2005-11-23 10:08 Rob Kirkbride <rob@rkcomputing.co.uk>
2005-11-23 10:57 ` Re: Switching user within connection. Oliver Jowett <oliver@opencloud.com>
0 siblings, 1 reply; 6+ messages in thread
From: Rob Kirkbride @ 2005-11-23 10:08 UTC (permalink / raw)
To: pgsql-jdbc
Hi,
Is there a standard way (or indeed a special way in Postgres) to switch
user/password without creating a new connection?
You can obviously do it within psql with \c but I wondered whether there
was a way in JDBC?
Thanks for any help,
Rob
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Switching user within connection.
2005-11-23 10:08 Switching user within connection. Rob Kirkbride <rob@rkcomputing.co.uk>
@ 2005-11-23 10:57 ` Oliver Jowett <oliver@opencloud.com>
2005-11-23 11:09 ` Re: Switching user within connection. Rob Kirkbride <rob@rkcomputing.co.uk>
0 siblings, 1 reply; 6+ messages in thread
From: Oliver Jowett @ 2005-11-23 10:57 UTC (permalink / raw)
To: Rob Kirkbride <rob@rkcomputing.co.uk>; +Cc: pgsql-jdbc
Rob Kirkbride wrote:
> Is there a standard way (or indeed a special way in Postgres) to switch
> user/password without creating a new connection?
> You can obviously do it within psql with \c but I wondered whether there
> was a way in JDBC?
There is no standard JDBC way I know of, short of reconnecting.
AFAIK there's no way at the protocol level to reauthenticate as a
different user on an existing connection. I believe psql's \c command
actually establishes a new connection.
If you originally connected as the database superuser you could use SET
SESSION AUTHORIZATION to get a similar effect; see
http://www.postgresql.org/docs/8.1/static/sql-set-session-authorization.html.
-O
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Switching user within connection.
2005-11-23 10:08 Switching user within connection. Rob Kirkbride <rob@rkcomputing.co.uk>
2005-11-23 10:57 ` Re: Switching user within connection. Oliver Jowett <oliver@opencloud.com>
@ 2005-11-23 11:09 ` Rob Kirkbride <rob@rkcomputing.co.uk>
2005-11-23 11:30 ` Re: Switching user within connection. Oliver Jowett <oliver@opencloud.com>
0 siblings, 1 reply; 6+ messages in thread
From: Rob Kirkbride @ 2005-11-23 11:09 UTC (permalink / raw)
To: Oliver Jowett <oliver@opencloud.com>; +Cc: pgsql-jdbc
Oliver Jowett wrote:
> Rob Kirkbride wrote:
>
>> Is there a standard way (or indeed a special way in Postgres) to
>> switch user/password without creating a new connection?
>> You can obviously do it within psql with \c but I wondered whether
>> there was a way in JDBC?
>
>
> There is no standard JDBC way I know of, short of reconnecting.
>
> AFAIK there's no way at the protocol level to reauthenticate as a
> different user on an existing connection. I believe psql's \c command
> actually establishes a new connection.
>
> If you originally connected as the database superuser you could use
> SET SESSION AUTHORIZATION to get a similar effect; see
> http://www.postgresql.org/docs/8.1/static/sql-set-session-authorization.html.
>
>
Thanks for your reply. I think I'd guessed that would be the reply. It's
probably off topic really now but I wanted to maintain a series of
pooled connections but with potentially different users. I got lost
reading the JCA documentation which may do something clever but I'm
guessing if the underlying JDBC driver doesn't support it then there's
not a lot it can do really.
Rob
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Switching user within connection.
2005-11-23 10:08 Switching user within connection. Rob Kirkbride <rob@rkcomputing.co.uk>
2005-11-23 10:57 ` Re: Switching user within connection. Oliver Jowett <oliver@opencloud.com>
2005-11-23 11:09 ` Re: Switching user within connection. Rob Kirkbride <rob@rkcomputing.co.uk>
@ 2005-11-23 11:30 ` Oliver Jowett <oliver@opencloud.com>
2005-11-23 13:24 ` Re: Switching user within connection. Rob Kirkbride <rob@rkcomputing.co.uk>
0 siblings, 1 reply; 6+ messages in thread
From: Oliver Jowett @ 2005-11-23 11:30 UTC (permalink / raw)
To: Rob Kirkbride <rob@rkcomputing.co.uk>; +Cc: pgsql-jdbc
Rob Kirkbride wrote:
> Thanks for your reply. I think I'd guessed that would be the reply. It's
> probably off topic really now but I wanted to maintain a series of
> pooled connections but with potentially different users. I got lost
> reading the JCA documentation which may do something clever but I'm
> guessing if the underlying JDBC driver doesn't support it then there's
> not a lot it can do really.
My JCA is a bit rusty, but from memory the way you deal with this is by
implementing ManagedConnectionFactory.matchManagedConnections() to only
consider connections that have matching authentication info. So the
container can maintain a single pool of connections, but when it asks
the connector for a suitable connection authenticated as Joe then only
connections in the pool that are already authenticated as Joe are
considered.
You may end up needing more connections in the pool depending on the
actual usage pattern, but you don't need to reauthenticate on an
existing connection.
-O
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Switching user within connection.
2005-11-23 10:08 Switching user within connection. Rob Kirkbride <rob@rkcomputing.co.uk>
2005-11-23 10:57 ` Re: Switching user within connection. Oliver Jowett <oliver@opencloud.com>
2005-11-23 11:09 ` Re: Switching user within connection. Rob Kirkbride <rob@rkcomputing.co.uk>
2005-11-23 11:30 ` Re: Switching user within connection. Oliver Jowett <oliver@opencloud.com>
@ 2005-11-23 13:24 ` Rob Kirkbride <rob@rkcomputing.co.uk>
0 siblings, 0 replies; 6+ messages in thread
From: Rob Kirkbride @ 2005-11-23 13:24 UTC (permalink / raw)
To: Oliver Jowett <oliver@opencloud.com>; +Cc: pgsql-jdbc
Oliver Jowett wrote:
> Rob Kirkbride wrote:
>
>> Thanks for your reply. I think I'd guessed that would be the reply.
>> It's probably off topic really now but I wanted to maintain a series
>> of pooled connections but with potentially different users. I got
>> lost reading the JCA documentation which may do something clever but
>> I'm guessing if the underlying JDBC driver doesn't support it then
>> there's not a lot it can do really.
>
>
> My JCA is a bit rusty, but from memory the way you deal with this is
> by implementing ManagedConnectionFactory.matchManagedConnections() to
> only consider connections that have matching authentication info. So
> the container can maintain a single pool of connections, but when it
> asks the connector for a suitable connection authenticated as Joe then
> only connections in the pool that are already authenticated as Joe are
> considered.
>
> You may end up needing more connections in the pool depending on the
> actual usage pattern, but you don't need to reauthenticate on an
> existing connection.
>
Thanks for you help - I see yes what you've given would be helpful.
However I'm struggling at the moment to work out how to configure JCA on
JBoss using Hibernate. But I guess that's a question for another forum!
Thanks again Oliver.
Rob
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Switching user within connection.
@ 2005-11-23 11:10 Rob Kirkbride <rob@rkcomputing.co.uk>
0 siblings, 0 replies; 6+ messages in thread
From: Rob Kirkbride @ 2005-11-23 11:10 UTC (permalink / raw)
To: smitha <smitha_alice_c@yahoo.com>; +Cc: pgsql-jdbc
smitha wrote:
> Hi Rob !!
>
> Just now I got ur Query. I will check it. I have doubt. If
> You know the answer for this Please reply to me. I am breaking my head
> to solve this.
>
> This is my Java Program. I get connected with the Postgresql Database
> and the query get executed and it affects in the Database.....A new
> user is created in the Database.. But i am getting the Exception "No
> result were returned by the query" what could be the reason.....Plz
> tell me
>
>
> // .java - example connection to a Postgresql (Database)
>
> import java.io.*;
> import java.sql.*;
>
> public class connect
> {
> public static String villageName = null;
> public static final boolean DEBUG = false;
>
> public static void main (String[] args)
> {
> //Ge t a Connection to Postgres
> try
> {
> Class.forName("org.postgresql.Driver");
> }
> catch (ClassNotFoundException e)
> {
> System.err.println( "Driver not found: " + e + "\n" +
> e.getMessage() );
> }
> try
> {
> String url="jdbc:postgresql://10.163.2.95:5432/collabland";
> Connection
> con=DriverManager.getConnection(url,"postgres","postgres");*
> Statement st=con.createStatement();
>
> String logName = "kala";
> String passwd = "kala";
>
> String query1 = "CREATE user " + logName + " with password '" +
> passwd + "' createuser";
> ResultSet rs= st.executeQuery(query1);
> System.out.println(query1);
> System.out.println("user created");
> }
> catch (SQLException sqlex)
> {
> if (DEBUG) sqlex.printStackTrace();
> System.out.println(sqlex.getMessage());
> // return false;
> }
> System.out.println("after catch block");
>
> }
> }
>
> *
(Correct top post - also please don't email off list)
I use the following syntax :
create user 'username' encrypted password 'password'
It works ok for me providing I don't try and use a prepared statement -
it doesn't seem to translate the $1 correctly in the username.
Rob
^ permalink raw reply [nested|flat] 6+ messages in thread
end of thread, other threads:[~2005-11-23 13:24 UTC | newest]
Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-11-23 10:08 Switching user within connection. Rob Kirkbride <rob@rkcomputing.co.uk>
2005-11-23 10:57 ` Oliver Jowett <oliver@opencloud.com>
2005-11-23 11:09 ` Rob Kirkbride <rob@rkcomputing.co.uk>
2005-11-23 11:30 ` Oliver Jowett <oliver@opencloud.com>
2005-11-23 13:24 ` Rob Kirkbride <rob@rkcomputing.co.uk>
2005-11-23 11:10 Re: Switching user within connection. Rob Kirkbride <rob@rkcomputing.co.uk>
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