FileDocCategorySizeDatePackage
TestPlaceHolder.javaAPI DocExample3958Thu Jun 28 21:37:16 BST 2001None

TestPlaceHolder

public class TestPlaceHolder extends Object

Fields Summary
Connection
conn
Constructors Summary
public TestPlaceHolder()

    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 TestPlaceHolder().process();
  
public voidprocess()

    int               rows   = 0;
    ResultSet         rslt   = null;
    PreparedStatement pstmt  = null;

    String            insert = 
     "insert into person_identifier_type " + 
     "( code, description, inactive_date ) " + 
     "values " + 
     "( ?, ?, ? )";
    String            update =
     "update person_identifier_type " + 
     "set    description = ? " + 
     "where  code = ?";
    String            delete = 
     "delete person_identifier_type " + 
     "where  code = ?";
    String            select = 
     "select ?, code, description " + 
     "from   person_identifier_type " +
     "where  code = ? " + 
     "order by ?";
    try {
      System.out.println(insert);
      pstmt = conn.prepareStatement(insert);
      pstmt.setString( 1, "SID" );
      pstmt.setString( 2, "Student Id" );
      pstmt.setNull( 3, Types.TIMESTAMP );
      rows = pstmt.executeUpdate();
      pstmt.close();
      pstmt = null;
      System.out.println(rows + " rows inserted");
      System.out.println("");
    }
    catch (SQLException e) {
      System.err.println(e.getMessage());
    }
    finally {
      if (pstmt != null) 
       try { pstmt.close(); } catch (SQLException ignore) { }
    }

    try {
      System.out.println(update);
      pstmt = conn.prepareStatement(update);
      pstmt.setString( 1, "Student ID" );
      pstmt.setString( 2, "SID" );
      rows = pstmt.executeUpdate();
      pstmt.close();
      pstmt = null;
      System.out.println(rows + " rows updated");
      System.out.println("");
    }
    catch (SQLException e) {
      System.err.println(e.getMessage());
    }
    finally {
      if (pstmt != null) 
        try { pstmt.close(); } catch (SQLException ignore) { }
    }

    try {
      System.out.println(select);
      pstmt = conn.prepareStatement(select);
      pstmt.setString( 1, "A CONSTANT" );
      pstmt.setString( 2, "SID" );
      pstmt.setString( 3, "A" );
      rslt = pstmt.executeQuery();
      rows = 0;
      while (rslt.next()) {
        rows++;
        System.out.print(rslt.getString(1) + " ");
        System.out.print(rslt.getString(2) + " ");
        System.out.println(rslt.getString(3));
      }
      pstmt.close();
      pstmt = null;
      System.out.println(rows + " rows selected");
      System.out.println("");
    }
    catch (SQLException e) {
      System.err.println(e.getMessage());
    }
    finally {
      if (rslt  != null) 
        try { rslt.close();  } catch (SQLException ignore) { }
      if (pstmt != null) 
        try { pstmt.close(); } catch (SQLException ignore) { }
    }

    try {
      System.out.println(delete);
      pstmt = conn.prepareStatement(delete);
      pstmt.setString( 1, "SID" );
      rows = pstmt.executeUpdate();
      pstmt.close();
      pstmt = null;
      System.out.println(rows + " rows deleted");
    }
    catch (SQLException e) {
      System.err.println(e.getMessage());
    }
    finally {
      if (pstmt != null) 
        try { pstmt.close(); } catch (SQLException ignore) { }
    }