Re: Something unusual has occured to cause the driver to fail. NullPointerException

From: Barry Lind <barry(at)xythos(dot)com>
To: Larry Rogers <larry(at)lwrogersjr(dot)org>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Something unusual has occured to cause the driver to fail. NullPointerException
Date: 2001-09-10 01:46:53
Message-ID: 3B9C1B8D.4020903@xythos.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Larry,

Shouldn't your connection URL be:

jdbc:postgresql://localhost:5432/testdb

instead of

jdbc:postgresql://localhost:5432?database=testdb

thanks,
--Barry

Larry Rogers wrote:
> Hi all,
>
> I'm having trouble opening a database connection to a test database on a
> fresh PostGreSQL 7.1.3 installation on RedHat 7.1 from the RPMs. I have a
> simple test class TestPostGreSQL that opens a connection, queries for all the
> rows in a table and prints the results to standard output. The driver file
> is in the same directory as the java class, which I execute using
>
> java -classpath .:jdbc7.1-1.2.jar TestPostGreSQL
>
> I get the following error message:
>
> Something unusual has occured to cause the driver to fail. Please report this
> exception: Exception: java.lang.NullPointerException
> Stack Trace:
> java.lang.NullPointerException
> at org.postgresql.Connection.openConnection(Connection.java:148)
> at org.postgresql.Driver.connect(Driver.java:122)
> at java.sql.DriverManager.getConnection(DriverManager.java:517)
> at java.sql.DriverManager.getConnection(DriverManager.java:177)
> at TestPostGreSQL.main(TestPostGreSQL.java:17)
> End of Stack Trace
>
> I created the database using
>
> createdb testdb
>
> and from psql created the table as
>
> create table Person (
> FirstName char(30) not null,
> LastName char(30) not null);
>
> then created the user and password and granted all permissions on the Person
> table.
>
> I start the server with
>
> postmaster -i
>
> to get TCP/IP support. The code for the test class is at the end of this
> message. Note that everything is commented out except for loading the driver
> and opening a connection. I have used JDBC successfully for months with
> Microsoft SQL Server, but I'm anxious to switch over to PostGreSQL!
>
> Thanks in advance for any help!
> Larry Rogers
>
> *****************************
>
> import java.sql.*;
> import java.util.Date;
>
> public class TestPostGreSQL {
>
> public static void main(String[] args) {
>
> final String driver = "org.postgresql.Driver";
> final String url = "jdbc:postgresql://localhost:5432?database=testdb";
> final String login = "TestUser";
> final String password = "TestPass";
> String sql = "SELECT * FROM Person";
>
> try {
> Class.forName(driver);
> Connection connection
> = DriverManager.getConnection(url, login, password);
> /*
>
> Statement statement = connection.createStatement();
> ResultSet result = statement.executeQuery(sql);
>
> while (result.next()) {
> System.out.println(result.getString("FirstName") + " " +
> result.getString("LastName"));
> }
> result.close();
> statement.close();
> */
> connection.close();
>
> } catch(SQLException e) {
> System.out.println(e);
> } catch(ClassNotFoundException e) {
> System.out.println(e);
> }
> }
> }
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://www.postgresql.org/search.mpl
>
>

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Barry Lind 2001-09-10 01:50:15 Re: [HACKERS] Troubles using German Umlauts with JDBC
Previous Message Larry Rogers 2001-09-10 01:39:44 Re: Something unusual has occured to cause the driver to fail. NullPointerException