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

From: Larry Rogers <larry(at)lwrogersjr(dot)org>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Something unusual has occured to cause the driver to fail. NullPointerException
Date: 2001-09-10 00:03:36
Message-ID: 01090919033602.08247@localhost.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

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);
}
}
}

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Bruce Momjian 2001-09-10 00:14:38 Re: [HACKERS] Troubles using German Umlauts with JDBC
Previous Message Rene Pijlman 2001-09-09 21:43:36 Re: Timezones and time/timestamp values in FE/BE protocol