columns.getString("COLUMN_NAME"); 

columns.getString("REMARKS");不是同一列你是否可以把你SQL写出来

解决方案 »

  1.   

    谢谢,不过好像没有SQL的啊。我可能没讲清楚,在讲细点。...
    //dbMetaData是由Connection得到的一个DatabaseMetaData,"table"
    //是数据库中一张表的名字
    ResultSet columns = dbMetaData.getColumns(null,
                         dbMetaData.getUserName(),
                         "table",
                         "%");
    while(columns.next()){
      //COLUMN_NAME和REMARKS是参考j2sdk文档上给出的列名
      System.out.println(columns.getString("COLUMN_NAME")+":"
                         +columns.getString("REMARKS"));
    }运行后,能得到列名,但是没有得到该列的comment。api文档:
    getColumns
    public ResultSet getColumns(String catalog,
                                String schemaPattern,
                                String tableNamePattern,
                                String columnNamePattern)
                         throws SQLException
    Retrieves a description of table columns available in the specified catalog. 
    Only column descriptions matching the catalog, schema, table and column name criteria are returned. They are ordered by TABLE_SCHEM, TABLE_NAME, and ORDINAL_POSITION. Each column description has the following columns: 1.TABLE_CAT String => table catalog (may be null) 
    2.TABLE_SCHEM String => table schema (may be null) 
    3.TABLE_NAME String => table name 
    4.COLUMN_NAME String => column name 
    5.DATA_TYPE int => SQL type from java.sql.Types 
    6.TYPE_NAME String => Data source dependent type name, for a UDT the type name is 
      fully qualified 
    7.COLUMN_SIZE int => column size. For char or date types this is the maximum 
      number of characters, for numeric or decimal types this is precision. 
    8.BUFFER_LENGTH is not used. 
    9.DECIMAL_DIGITS int => the number of fractional digits 
    10.NUM_PREC_RADIX int => Radix (typically either 10 or 2) 
    11.NULLABLE int => is NULL allowed. 
      *columnNoNulls - might not allow NULL values 
      *columnNullable - definitely allows NULL values 
      *columnNullableUnknown - nullability unknown 
    12.REMARKS String => comment describing column (may be null) 
    13.COLUMN_DEF String => default value (may be null) 
    ...................
      

  2.   

    我只知道ResultSetgetString
    public String getString(String columnName)
                     throws SQLExceptionRetrieves the value of the designated column in the current row of this ResultSet object as a String in the Java programming language. Parameters:
    columnName - the SQL name of the column 
    Returns:
    the column value; if the value is SQL NULL, the value returned is null 
    Throws: 
    SQLException - if a database access error occurs请问楼主是否将ResultSet.getString(String columnName) 改写了,还是楼主的
    ResultSet自己重新写了
      

  3.   

    请问楼主是否使用的是java.sql.ResultSet
      

  4.   

    那你下面用的是ResultSet.getString("COLUMN_NAME")你怎么可以用  getColumns(String catalog,
                                String schemaPattern,
                                String tableNamePattern,
                                String columnNamePattern)
    中的解释呢?
      

  5.   

    to 楼上:
    其实楼主的意思是:
    public ResultSet getColumns(String catalog,
                                String schemaPattern,
                                String tableNamePattern,
                                String columnNamePattern)
                         throws SQLException
    返回一个ResultSet,该ResultSet有Column_Name,res,TABLE_CAT等字段
    所以用columns.getString("COLUMN_NAME")+":"+columns.getString("REMARKS")是可以的啊。
      

  6.   

    对的,我就是这么个意思,:)
    只是columns.getString("REMARKS")的值一直是null