pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Rob Kirkbride <rob@rkcomputing.co.uk>
To: smitha <smitha_alice_c@yahoo.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: Switching user within connection.
Date: Wed, 23 Nov 2005 11:10:28 +0000
Message-ID: <43844E24.3030700@rkcomputing.co.uk> (raw)
In-Reply-To: <20051123101605.72289.qmail@web60221.mail.yahoo.com>
References: <20051123101605.72289.qmail@web60221.mail.yahoo.com>


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




view thread (6+ messages)  latest in thread

Message-ID: <43844E24.3030700@rkcomputing.co.uk>
Permalink:  ../43844E24.3030700@rkcomputing.co.uk/
Also on:    postgresql.org/message-id/43844E24.3030700@rkcomputing.co.uk

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: rob@rkcomputing.co.uk, smitha_alice_c@yahoo.com
  Subject: Re: Switching user within connection.
  In-Reply-To: <43844E24.3030700@rkcomputing.co.uk>
  References: <20051123101605.72289.qmail@web60221.mail.yahoo.com> <43844E24.3030700@rkcomputing.co.uk>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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