FileDocCategorySizeDatePackage
DefineColumnType.javaAPI DocExample1886Wed Sep 17 13:49:50 BST 1997None

DefineColumnType

public class DefineColumnType extends Object

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)

    // Load the Oracle JDBC driver
    DriverManager.registerDriver( new oracle.jdbc.driver.OracleDriver());

    // Connect to the database
    // You can put a database name after the @ sign in the connection URL.
    Connection conn =
      DriverManager.getConnection ("jdbc:oracle:oci7:@", "scott", "tiger");

    Statement stmt = conn.createStatement ();

    // Call DefineColumnType to specify that the column will be
    // retrieved as a String to avoid conversion from NUMBER to String
    // on the client side.  This also avoids a round-trip to the
    // database to get the column type.
    //
    // There are 2 defineColumnType API.  We use the one with 3 arguments.
    // The 3rd argument allows us to specify the maximum length
    // of the String.  The values obtained for this column will
    // not exceed this length.

    ((OracleStatement)stmt).defineColumnType (1, Types.VARCHAR, 2);

    ResultSet rset = stmt.executeQuery ("select empno from emp");
    while (rset.next ())
    {
      System.out.println (rset.getString (1));
    }
    stmt.close ();