NonStop Server for Java (NSJ) Programmer's Guide (NSJ 2.1+)
Dangling Statements
SQL/MP drivers track all statements within a connection, but when an exception occurs, Java's garbage collection feature
might prevent a driver from immediately closing an open statement. A statement that is left dangling inside a connection could
cause unexpected results.
To avoid dangling statements:
Create statements outside try-catch blocks.● 
Close statements when they are no longer needed.● 
In the following example, if executeQuery() throws an exception, the statement inside the try-catch block might be
left dangling:
try {
 Statement stmt = conn.createStatement();
 ResultSet rs = stmt.executeQuery("drop table usertable");
}
catch (SQLException sqlex) {
 // error handling
}
The following example is like the preceding example except that it declares the statement outside the try-catch block. If
executeQuery() throws an exception, the statement is not left dangling.
Statement stmt;
ResultSet rs;
try {
 stmt = conn.createStatement();
 ResultSet rs = stmt.executeQuery("drop table usertable");
}
catch (SQLException sqlex) {
 // error handling
}
finally {
 stmt.close();
}
Sample SQL/MP Program
The following Java program connects itself to an SQL/MP database, sends a simple select statement to the database, and
processes the results:
import java.sql.*;
class sqlmpExample {
 // Load SQL/MP driver the first time, so you do not have to specify 
 // -Djava.drivers=com.tandem.sqlmp.SQLMPDriver when running java.
 static {
 try {
 Class.forName("com.tandem.sqlmp.SQLMPDriver");
 } catch (Exception ex) {}
 }
 public static void main(String argv[]) throws SQLException {










