select * from sysobjects where type="U"  //MSSQL

解决方案 »

  1.   

    test----------你的selcet语句访问的不就是表名码?呵呵
      

  2.   

    test----------你的selcet语句访问的不就是表名码?呵呵
      

  3.   

    不是啊! 必须用方法的!  我不能确定 SQL 语句到底是什么 !我能得到的只是 ResultSet 对象啊!  帮帮忙!
      

  4.   

    String tablename=rsm.getTableName(1);
      

  5.   

    select * from cat;
    // cat 就是Oracle的管理表。
      

  6.   

    rsm.getTableName(1);   但这个返回的空的啊! 怎么半呢?
      

  7.   

    有没有搞错,怎么会凭空得到一个结果集的对象呢?,如果是传来的,那就 ,在把表名也传来把。
    to :bill_hongs(hongs) -----用String tablename=rsm.getTableName(1);
    得到的该是指定的列的名字吧。?
      

  8.   

    to qxjavajava(射手座 =---> 恭喜发财) :使用 rsm.getColumnName 等其他的都可以! 但rsm.getTableName(1)是不行的! 是空的!怎么办啊?
      

  9.   

    MS SQLServer 的好几个存储过程都不错,或者从 master 的表里获取,但是最好的方法是使用 JDBC 的 DataBaseMeta 类。
    下面是我写的一个程序中的用来获取 TablesName 的一个方法:
    /**
     * getDBTables()
     * @param DataOutputStream outFile
     * @return boolean
     */
    public boolean getDBTables(String DBName)
    {
    Connection conn = getConnection();
    if ( conn == null ) 
    return false;

    try
    {
    DatabaseMetaData dm = conn.getMetaData();
    String[] objCategories = {"TABLE"};
    ResultSet rs = dm.getTables(DBName,null,"%",objCategories); printHTML("<table cellSpacing='1' cellPadding='3' width='600' bgColor='white' border='1' bordercolor='#006699' style='border-collapse: collapse; border-style: solid; font-size:10.5pt' id='DB_" + DBName +"'>");
    printHTML("<tr bgColor='#e6e6e6'><td colspan='3'><b>数据库&nbsp;&nbsp;" + DBName + "&nbsp;&nbsp;&nbsp;&nbsp;数据结构</b></td></tr>");
    printHTML("<tr bgColor='#cce6ff'><td width='50'><b>用户表</b></td><td>&nbsp;</td><td align='right'>< ></td></tr>");

    while(rs.next())
    {
    printHTML("\t<tr height='2'><td colspan='3'></td></tr>"); String dbObjectName = rs.getString(3);
    String dbObjectType = rs.getString(4);

    printHTML("\t<tr id='TBL_" + dbObjectName + "' bgColor='#e6e6e6'>");
    printHTML("\t\t<td width='80'>");
    printHTML("\t\t\t<b>表名</b>");
    printHTML("\t\t</td>");
    printHTML("\t\t<td>");
    printHTML("\t\t\t<b>" + dbObjectName);
    printHTML("\t\t</b></td>");
    printHTML("\t\t<td align='right' width='80'><a href='javascript:showTable(\"" + dbObjectName + "\");'>收缩</a> <a href='javascript:hideTable(\"" + dbObjectName + "\");'>展开</a></td>");
    printHTML("\t</tr>");
    printHTML("\t<tr id='TBLC_" + dbObjectName + "' style='display:\"\"'>");
    printHTML("\t\t<td colspan='3'>");

    //Enum Columns in Table
    getTableColumns(DBName,dbObjectName);

    printHTML("\t\t</td>");
    printHTML("\t</tr>");
    }
    printHTML("</table>"); rs.close();
    conn.close();

    }
    catch(SQLException sqle)
    {
    RaiseErrorMessage("getDBTables Error: " + sqle.getMessage());
    }
    catch(Exception e)
    {
    RaiseErrorMessage("getDBTables Error: " + e.getMessage());
    }
    return true;
    }----------------------------------------------
    关键用法如下:
    DatabaseMetaData dm = conn.getMetaData();
    String[] objCategories = {"TABLE"};
    ResultSet rs = dm.getTables(DBName,null,"%",objCategories);
    ______________________________________________
    getTables public ResultSet getTables(String catalog,
                               String schemaPattern,
                               String tableNamePattern,
                               String[] types)
                        throws SQLException Gets a description of tables available in a catalog. Only table descriptions matching the catalog, schema, table name and type criteria are returned. They are ordered by TABLE_TYPE, TABLE_SCHEM and TABLE_NAME. Each table description has the following columns: TABLE_CAT String => table catalog (may be null) TABLE_SCHEM String => table schema (may be null) TABLE_NAME String => table name TABLE_TYPE String => table type. Typical types are "TABLE", "VIEW", "SYSTEM TABLE", "GLOBAL TEMPORARY", "LOCAL TEMPORARY", "ALIAS", "SYNONYM". REMARKS String => explanatory comment on the table Note: Some databases may not return information for all tables.Parameters:catalog - a catalog name; "" retrieves those without a catalog; null means drop catalog name from the selection criteriaschemaPattern - a schema name pattern; "" retrieves those without a schematableNamePattern - a table name patterntypes - a list of table types to include; null returns all typesReturns:ResultSet - each row is a table descriptionThrows:SQLException - if a database access error occurs
      

  10.   

    ADO里面其实也有一个
    DM 对象用来干这个。for SQLServer 功能强大到足以实现大部分企业管理器的功能。如果要脱离数据库依赖,最好使用JDBC本身的技术来解决,而不是某个数据库系统提供的存储过程。
      

  11.   

    to: piggybank(吞硬币的小猪) 你用的什么驱动啊! 我怕是我的驱动不对!
      

  12.   

    不会吧, java.sql.DatabaseMetaData 都没有?
    呵呵,careless说得没错儿,如果是join查询或者是多次复合查询的结果,RS中如何知道是从哪个表打开的?
    我回答的问题是:枚举某个数据库中的表名
    同样可以用DatabaseMetaData枚举某个表的存储过程、视图、字段等等。