FileDocCategorySizeDatePackage
HandlingNullValues3.javaAPI DocExample1883Sat Jun 23 17:20:16 BST 2001None

HandlingNullValues3

public class HandlingNullValues3 extends Object

Fields Summary
Connection
conn
Constructors Summary
public HandlingNullValues3()

    try {
      DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
      conn = DriverManager.getConnection(
       "jdbc:oracle:thin:@dssw2k01:1521:orcl", "scott", "tiger");
    }
    catch (SQLException e) {
      System.err.println(e.getMessage());
      e.printStackTrace();
    }
  
Methods Summary
protected voidfinalize()

    if (conn != null) 
      try { conn.close(); } catch (SQLException ignore) { }
    super.finalize();
  
public static voidmain(java.lang.String[] args)

    new HandlingNullValues3().process();
  
public voidprocess()

    // dNull is the agreed upon flag value for a NULL from the database
    double     dNull    = -1.0;
    double     adouble;
    int        rows     = 0;
    ResultSet  rslt     = null;
    Statement  stmt     = null;
    try {
      stmt = conn.createStatement();
      rslt = stmt.executeQuery(
       "select to_number( NULL ) from sys.dual");
      if (rslt.next()) {
        rows++;

        adouble = rslt.getDouble(1);

        System.out.println("before wasNull() a double = " + adouble);

        if (rslt.wasNull()) 
          adouble = dNull;

        System.out.println("after  wasNull() a double = " + adouble);
      }
      rslt.close();
      rslt = null;
      stmt.close();
      stmt = null;
    }
    catch (SQLException e) {
      System.err.println(e.getMessage());
    }
    finally {
      if (rslt != null) 
        try { rslt.close(); } catch (SQLException ignore) { }
      if (stmt != null) 
        try { stmt.close(); } catch (SQLException ignore) { }
    }