在java里,用ResultSetMetaData类的getColumnName(int i)可以得到列名desc area_table ?你要把这个表倒序排?

解决方案 »

  1.   

    to:bobosji(波波司机) 
    desc area_table 是显示table的结构。
    ResultSet rs = stmt.exeQuery("select * from area_talbe");//stmt 是statement对象。
    ResultSetMetaData rsmd = rs.getMetaData();
    int numCols = rsmd.getColumnCount();  //get the number of columns
    for ( int i =1;i<=numCols;i++){
       if (i>1) System.out.print(",");
       System.out.print(rsmd.getColumnLabel(i));//显示每个列的标题
    }
    System.out.println("");  }
      

  2.   

    方法:getColumnName
    public String getColumnName(int column) throws SQLException**Get the designated column's name.方法:getColumnLabel
    public String getColumnLabel(int column) throws SQLException**Gets the designated column's suggested title for use in printouts and displays.如果是要显示你的中文列名,用getColumnLabel;
    如果要根据列名来取数据,用getColumnName。另:to pang:
    desc area_table 是哪里的用法?
      

  3.   

    用ResultSetMetaData类的getColumnCount()
      

  4.   

    记得要catch  SQLException
      

  5.   

    to bobosji(波波司机) 
    desc命令在oracle和sqlserver都可。是标准的sql文。
    后接表名。用来显示表的结构。 
      

  6.   

    主要看你用什么数据库了,ORACLE中有一些系统表,可以读出表名,列名的。
    其他的数据库,我就不知道了!
      

  7.   

    以下是我程序中的一个SQL语句,这个SQL语句就是用来读出DbName表的列名和列号了。
    SQL_SEL_FIELDS = "SELECT * FROM DBA_TAB_COLUMNS WHERE TABLE_NAME = '" + DbName.toUpperCase() +"' ORDER BY COLUMN_ID";
      

  8.   

    to pang:
    原来如此,我只晓得有describe,不晓得还可以缩写的,还以为是descending呢,呵呵
      

  9.   

    to panq & bobosji:
    不知道sysbase里有没有这种表?
    用上面的语句可以读出某一个表的所有列名
      

  10.   

    getColumnType
    public int getColumnType(int column)
                      throws SQLException
    Retrieves the designated column's SQL type.
    Parameters:
    column - the first column is 1, the second is 2, ...
    Returns:
    SQL type from java.sql.Types
    Throws:
    SQLException - if a database access error occurs
    See Also: 
    Types--------------------------------------------------------------------------------getColumnTypeName
    public String getColumnTypeName(int column)
                             throws SQLException
    Retrieves the designated column's database-specific type name.
    Parameters:
    column - the first column is 1, the second is 2, ...
    Returns:
    type name used by the database. If the column type is a user-defined type, then a fully-qualified type name is returned.
    Throws:
    SQLException - if a database access error occurs