论坛首页 Java企业应用论坛

DatabaseMetaData类中getProcedureColumns方法的使用

浏览 3833 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2007-08-13  
DAO

最近写一个可以在运行期获得存储过程输入参数的类,找到一个方法

public ResultSet getProcedureColumns(String catalog,
                                     String schemaPattern,
                                     String procedureNamePattern,
                                     String columnNamePattern)
                              throws SQLException
Retrieves a description of the given catalog's stored procedure parameter and result columns.

Only descriptions matching the schema, procedure and parameter name criteria are returned. They are ordered by PROCEDURE_SCHEM and PROCEDURE_NAME. Within this, the return value, if any, is first. Next are the parameter descriptions in call order. The column descriptions follow in column number order.

Each row in the ResultSet is a parameter description or column description with the following fields:

  1. PROCEDURE_CAT String => procedure catalog (may be null)
  2. PROCEDURE_SCHEM String => procedure schema (may be null)
  3. PROCEDURE_NAME String => procedure name
  4. COLUMN_NAME String => column/parameter name
  5. COLUMN_TYPE Short => kind of column/parameter:
    • procedureColumnUnknown - nobody knows
    • procedureColumnIn - IN parameter
    • procedureColumnInOut - INOUT parameter
    • procedureColumnOut - OUT parameter
    • procedureColumnReturn - procedure return value
    • procedureColumnResult - result column in ResultSet
  6. DATA_TYPE int => SQL type from java.sql.Types
  7. TYPE_NAME String => SQL type name, for a UDT type the type name is fully qualified
  8. PRECISION int => precision
  9. LENGTH int => length in bytes of data
  10. SCALE short => scale
  11. RADIX short => radix
  12. NULLABLE short => can it contain NULL.
    • procedureNoNulls - does not allow NULL values
    • procedureNullable - allows NULL values
    • procedureNullableUnknown - nullability unknown
  13. REMARKS String => comment describing parameter/column

catalog是你的存储过程的package,如果没有传null,schemaPattern是你的schema名称,不确定的话也是可以传null,procedureNamePattern是你存储过程的名称,这个不能没有了,columnNamePattern不清楚,但是可以为null,可以传"%"表示任意字符。

但是关键是:所有这些参数,如果有的话,一律要大写,不管你定义的时候是什么样的。否则他取不出值来的,至少在oracle上是这样的,这个浪费了我N多时间。

联想到一般数据库的表名和字段都是大小写不敏感的,在这里突然来一个大小写敏感,实在是不合理。

论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics