Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 7976C63521E for ; Wed, 10 Mar 2010 21:56:14 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 57144-01 for ; Thu, 11 Mar 2010 01:56:03 +0000 (UTC) Received: from news.hub.org (news.hub.org [200.46.204.72]) by mail.postgresql.org (Postfix) with ESMTP id E8695634D51 for ; Wed, 10 Mar 2010 21:56:03 -0400 (AST) Received: from news.hub.org (news.hub.org [200.46.204.72]) by news.hub.org (8.14.3/8.14.3) with ESMTP id o2B1tvGK075017 for ; Wed, 10 Mar 2010 21:55:58 -0400 (AST) (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.14.3/8.14.3/Submit) id o2B1j5Sl071655 for pgsql-jdbc@postgresql.org; Wed, 10 Mar 2010 21:45:05 -0400 (AST) (envelope-from news) From: Lew X-Newsgroups: pgsql.interfaces.jdbc Subject: Re: org.postgresql.util.PSQLException: Protocol error. Session setup failed Date: Wed, 10 Mar 2010 20:45:08 -0500 Organization: albasani.net Lines: 67 Message-ID: References: <375c2da1003090851h36daef83v2ced94b02051b08b@mail.gmail.com> <4B967DB4.8090104@ttc-cmc.net> <375c2da1003090941l5160381fq3d6790ad389ea51a@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@albasani.net X-User-ID: oNNKnt5w/6lalJh0IXskgqJIgGx8D2gyyP/ggYLnArw= In-Reply-To: <375c2da1003090941l5160381fq3d6790ad389ea51a@mail.gmail.com> Cancel-Lock: sha1:8h74zVmsrMAl0hVUUoVJ0jrNYWw= User-Agent: Thunderbird 2.0.0.23 (X11/20090817) X-NNTP-Posting-Host: WzeOWoNsW3855Rib68Bbl3km9U409w6RLYwXX8DCqGk= To: pgsql-jdbc@postgresql.org X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.001 tagged_above=-10 required=5 tests=BAYES_50=0.001 X-Spam-Level: X-Archive-Number: 201003/49 X-Sequence-Number: 20389 Major Services wrote: > Output is : Output of what? > //============================================================ // Main > public access point method for instantiating the // PostgreSQL_JDBC > application. Arguments: database, username, // & password. // > ============================================================== public > static void main(String[] args) throws SQLException, > InstantiationException, IllegalAccessException, ClassNotFoundException, > InterruptedException { String host, database, username, password; > Connection dbConnection; // Collect connection properties. and setup > connection. //host = "cindy"; host = "localhost"; if (args.length != 0) > { database = args[0]; username = (args.length > 1) ? args[1] : null; > password = (args.length > 2) ? args[2] : null; } else { database = > "postgres"; username = "postgres"; password = "major"; } dbConnection = > null; Class.forName("org.postgresql.Driver").newInstance(); dbConnection > = DriverManager.getConnection("jdbc:postgresql://" + host + "/" + > database, username, password); System.out.println("Connection Created"); > new PostgreSQL_JDBC(dbConnection); // Close. dbConnection.close(); > System.out.println("Connection Closed"); } Wow, that is some unreadable source code. I see nothing here that sheds light on your question, though. What caught my eye in what dmp wrote: is > public static void main(String[] args) throws SQLException, > InstantiationException, > IllegalAccessException, ClassNotFoundException, > InterruptedException If you don't handle the exceptions, perhaps even with logging, it's harder to diagnose what went wrong. I am also curious why the declaration of 'InterruptedException' is in the throws list. > { > String host, database, username, password; > Connection dbConnection; Declared but not instantiated - correct enough except that ... > dbConnection = null; assigned here, then > Class.forName("org.postgresql.Driver").newInstance(); > dbConnection = DriverManager.getConnection("jdbc:postgresql://" > + host + "/" + database, username, > password); the value is replaced here. It's a best practice in Java to declare variables within the scope of use, and close to the point of use. It doesn't make much sense to assign a value to the variable that is never used, just thrown away. Also that argument applies to the invocation of 'newInstance()'. The driver registers itself with the driver manager on class initialization; the creation of an instance does nothing but waste time. User code never directly uses driver instances. -- Lew