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:
        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 

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 {
            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") + " " + 

        } catch(SQLException e) {
        } catch(ClassNotFoundException e) {

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?


Reply via email to