pg.ddx.io pgsql-interfaces@postgresql.org mailing list archive
help / color / mirror / Atom feedPostgresql JDBC errors
2+ messages / 2 participants
[nested] [flat]
* Postgresql JDBC errors
@ 2000-04-18 04:16 Nick Rathke <render@uswest.net>
0 siblings, 0 replies; 2+ messages in thread
From: Nick Rathke @ 2000-04-18 04:16 UTC (permalink / raw)
To: pgsql-interfaces
I an using Postgresql-6.5.3 with jdbc6.5-1.2 and jdk1.2.2 on redhat
linux 6.2 . I
have tried to check the jdbc link using JDBCtest.java. Here is the info.
my classpath is
CLASSPATH=/lib/jdbc6.5-1.1.jar
JDBCtest.java
/*
This file is part of the tutorial in Chapter 3 of "Getting Started
with Enhydra".
It is not meant to be used in any other context.
Simple program to test JDBC connectivity. Assumes you have created
and populated
a table called LE_TUTORIAL_DISCS in your database.
Edit the connection string in the call to
DriverManager.getConnection()/
*/
import java.sql.*;
public class JDBCTest {
public static void main( String[] args ) {
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
// Load the driver, get a connection, create statement, run query, and
print.
try {
Class.forName("postgresql.Driver");
// Replace parameters below your database connection string,
username, and password
con = DriverManager.getConnection("jdbc:postgresql:dbtest"
,"appserver", "appserver" );
stmt = con.createStatement();
rs = stmt.executeQuery("SELECT * FROM LE_TUTORIAL_DISCS");
rs.next();
System.out.println("Title = " + rs.getString("title") + " -- Artist =
" + rs.getString("artist"));
}
catch(ClassNotFoundException e) {
System.err.println("Couldn't load the driver: " + e.getMessage());
}
catch(SQLException e) {
System.err.println("SQLException caught: " + e.getMessage());
}
}
}
which gives me the errors:
Exception in thread "main" java.lang.NullPointerException:
at
postgresql.jdbc2.ResultSet.getString(ResultSet.java:148)
at
postgresql.jdbc2.ResultSet.getString(ResultSet.java:531)
at JDBCTest.main(JDBCTest.java:25)
I don't know enough about Java or databases to make any sense of this.
Any help would be great.
Nick Rathke
^ permalink raw reply [nested|flat] 2+ messages in thread
* RE: Postgresql JDBC errors
@ 2000-04-18 07:19 Peter Mount <petermount@it.maidstone.gov.uk>
0 siblings, 0 replies; 2+ messages in thread
From: Peter Mount @ 2000-04-18 07:19 UTC (permalink / raw)
To: 'Nick Rathke' <render@uswest.net>; pgsql-interfaces
Which line is line 25 exactly?
Technically after the executeQuery(), rs may be null, so you should wrap
the next two lines in an if statement. ie:
rs = stmt.executeQuery("SELECT * FROM LE_TUTORIAL_DISCS");
if(rs) {
rs.next();
System.out.println("Title = " + rs.getString("title") + " -- Artist =
" + rs.getString("artist"));
rs.close(); // note to close the ResultSet
}
Peter
--
Peter Mount
Enterprise Support
Maidstone Borough Council
Any views stated are my own, and not those of Maidstone Borough Council.
-----Original Message-----
From: Nick Rathke [mailto:render@uswest.net]
Sent: Tuesday, April 18, 2000 5:17 AM
To: pgsql-interfaces@postgresql.org
Subject: [INTERFACES] Postgresql JDBC errors
I an using Postgresql-6.5.3 with jdbc6.5-1.2 and jdk1.2.2 on redhat
linux 6.2 . I
have tried to check the jdbc link using JDBCtest.java. Here is the info.
my classpath is
CLASSPATH=/lib/jdbc6.5-1.1.jar
JDBCtest.java
/*
This file is part of the tutorial in Chapter 3 of "Getting Started
with Enhydra".
It is not meant to be used in any other context.
Simple program to test JDBC connectivity. Assumes you have created
and populated
a table called LE_TUTORIAL_DISCS in your database.
Edit the connection string in the call to
DriverManager.getConnection()/
*/
import java.sql.*;
public class JDBCTest {
public static void main( String[] args ) {
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
// Load the driver, get a connection, create statement, run query, and
print.
try {
Class.forName("postgresql.Driver");
// Replace parameters below your database connection string,
username, and password
con = DriverManager.getConnection("jdbc:postgresql:dbtest"
,"appserver", "appserver" );
stmt = con.createStatement();
rs = stmt.executeQuery("SELECT * FROM LE_TUTORIAL_DISCS");
rs.next();
System.out.println("Title = " + rs.getString("title") + " -- Artist =
" + rs.getString("artist"));
}
catch(ClassNotFoundException e) {
System.err.println("Couldn't load the driver: " + e.getMessage());
}
catch(SQLException e) {
System.err.println("SQLException caught: " + e.getMessage());
}
}
}
which gives me the errors:
Exception in thread "main" java.lang.NullPointerException:
at
postgresql.jdbc2.ResultSet.getString(ResultSet.java:148)
at
postgresql.jdbc2.ResultSet.getString(ResultSet.java:531)
at JDBCTest.main(JDBCTest.java:25)
I don't know enough about Java or databases to make any sense of this.
Any help would be great.
Nick Rathke
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2000-04-18 07:19 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2000-04-18 04:16 Postgresql JDBC errors Nick Rathke <render@uswest.net>
2000-04-18 07:19 RE: Postgresql JDBC errors Peter Mount <petermount@it.maidstone.gov.uk>
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