zoukankan      html  css  js  c++  java
  • JDBC杂烩饭

    Registering Output Parameters

    The type codes in java.sql.Types or oracle.jdbc.OracleTypes identify the
    SQL types of the output parameters in the registerOutParameter method of the
    java.sql.CallableStatement and
    oracle.jdbc.OracleCallableStatement interfaces.
    These are the forms that the registerOutputParameter method can take for the
    CallableStatement and OracleCallableStatement interfaces
    cs.registerOutParameter(int index, int sqlType);
    cs.registerOutParameter(
    int index, int sqlType, String sql_name);
    cs.registerOutParameter(
    int index, int sqlType, int scale);
    In these signatures, index represents the parameter index, sqlType is the type code
    for the SQL data type, sql_name is the name given to the data type, for user-defined
    types, when sqlType is a STRUCT, REF, or ARRAY type code, and scale represents
    the number of digits to the right of the decimal point, when sqlType is a NUMERIC or
    DECIMAL type code.
    setNull Method
    The type codes in Types and OracleTypes identify the SQL type of the data item,
    which the setNull method sets to NULL. The setNull method can be found in the
    java.sql.PreparedStatement and
    oracle.jdbc.OraclePreparedStatement interfaces.
    These are the forms that the setNull method can take for the PreparedStatement
    and OraclePreparedStatement objects:
    ps.setNull(int index, int sqlType);
    ps.setNull(
    int index, int sqlType, String sql_name);
    In these signatures, index represents the parameter index, sqlType is the type code
    for the SQL data type, and sql_name is the name given to the data type, for
    user-defined types, when sqlType is a STRUCT, REF, or ARRAY type code. If you enter
    an invalid sqlType, a ParameterTypeConflict exception is thrown.
    The following example uses a prepared statement to insert a null value into the
    database. Note the use of OracleTypes.NUMERIC to identify the numeric object set
    to NULL. Alternatively, Types.NUMERIC can be used.
    Method setFixedCHAR for Binding CHAR Data into WHERE Clauses
    CHAR data in the database is padded to the column width. This leads to a limitation in
    using the setCHAR method to bind character data into the WHERE clause of a SELECT
    statement. The character data in the WHERE clause must also be padded to the column
    width to produce a match in the SELECT statement. This is especially troublesome if
    you do not know the column width.
    To remedy this, Oracle has added the setFixedCHAR method to the
    OraclePreparedStatement class. This method runs a non-padded comparison.
    OraclePreparedStatement pstmt=(OraclePreparedStatement) conn.prepareStatement("select count(*) from my_table where col1=?");
    pstmt.setFixedCHAR(
    1, "JDBC");

    //or method 2nd
    OraclePreparedStatement pstmt=(OraclePreparedStatement) conn.prepareStatement("select count(*) from my_table where trim(col1)=?");
    pstmt.setString(
    1, "JDBC");

      

  • 相关阅读:
    于丹关于人性的总结
    Oracle中的MS SQLSERVER@@ERROR
    分享2011年10月网上随机搜集的超酷超有趣的web开发和Javascript代码
    来自Nike Better World的视差滚动(Parallax Scrolling)特效 分享一些教程和灵感
    2011年最新使用CSS3实现各种独特悬浮效果的教程
    分享2011年50个最棒的wordpress主题 第一部分
    分享2011年50个最棒的wordpress主题
    分享一个超酷创建互动文档的Javascript类库 tangle
    jQuery Howto: 如何快速创建一个AJAX的"加载"的图片效果
    什么时候我们该选择VPS服务器?
  • 原文地址:https://www.cnblogs.com/freewater/p/2156247.html
Copyright © 2011-2022 走看看