FileDocCategorySizeDatePackage
TestDefineParameterType.javaAPI DocExample2550Mon Jul 02 20:34:12 BST 2001None

TestDefineParameterType

public class TestDefineParameterType extends Object

Fields Summary
Connection
conn
Constructors Summary
public TestDefineParameterType()

    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 TestDefineParameterType().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            delete = 
     "delete person_identifier_type " + 
     "where  code = ?";
    
    try {
      System.out.println(insert);
      pstmt = conn.prepareStatement(insert);

      ((OraclePreparedStatement)pstmt).defineParameterType(
       1, Types.VARCHAR, 30);

      ((OraclePreparedStatement)pstmt).defineParameterType(
       2, Types.VARCHAR, 80);

      pstmt.setString( 1, "SID" );
      pstmt.setString( 2, "Student Id" );
      pstmt.setNull( 3, Types.TIMESTAMP );
      rows = pstmt.executeUpdate();
      System.out.println(rows + " rows inserted");
      System.out.println("");
      pstmt.close();
      pstmt = null;
    }
    catch (SQLException e) {
      System.err.println(e.getMessage());
    }
    finally {
      if (pstmt != null) 
        try { pstmt.close(); } catch (SQLException ignore) { }
    }

    try {
      System.out.println(delete);
      pstmt = conn.prepareStatement(delete);

      ((OraclePreparedStatement)pstmt).defineParameterType(
       1, Types.VARCHAR, 30);

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