Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Problem closing JDBC connection

843854Mar 26 2003 — edited Mar 29 2004
All

I am able to successfully establish a connection to a DB2 database, but when I try to close the connection I get a NullPointerException. This is just a simple test program using the following code:

public Conn()
{
String query = "SELECT CUSNBR FROM ECLIB.CUSUSRMP";

System.out.println("Making new Conn object...");
try
{
System.out.println("Calling getDbConnection() method...");
if (conn == null)
{
Class.forName("com.ibm.as400.access.AS400JDBCDriver");
System.out.print("Connecting...");
conn = DriverManager.getConnection("jdbc:as400://ATIESRV1;prefetch=true;prompt=false", USER, PASSWORD);
conn.setAutoCommit(false);
System.out.println("Connected to AS/400.");

Statement st = conn.createStatement();
ResultSet rs = st.executeQuery(query);

while(rs.next())
{
String name = rs.getInt("CUSNBR");
System.out.println("Name: " + name);
}

System.out.println("Attempting to close the connection...");
// closing connections/Objects
if (conn != null)
{
System.out.println("conn is NOT null");
rs.close();
st.close();
conn.close();
}
System.out.println("Connection successfully closed !!!");
}
}
catch(AS400JDBCException e)
{
System.out.println("AS400JDBCException occurred: " + e.getMessage());
e.printStackTrace();
}
catch(SQLException e)
{
System.out.println("SQLException occurred: " + e.getMessage());
e.printStackTrace();
}
catch(NullPointerException e)
{
System.out.println("NullPointerException occurred: " + e.getMessage());
}
catch(Exception e)
{
System.out.println("General Exception occurred: " + e.getMessage());
}
}

I don't see the problem. Why is this happening ???
Thanks ...
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 26 2004
Added on Mar 26 2003
10 comments
441 views