类:public interface java.sql.DatabaseMetaData方法:getTables 具体如下:public ResultSet getTables(String catalog,
                           String schemaPattern,
                           String tableNamePattern,
                           String[] types)
                    throws SQLExceptionEach table 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.TABLE_TYPE String => table type. Typical types are "TABLE", "VIEW", "SYSTEM TABLE", "GLOBAL TEMPORARY", "LOCAL TEMPORARY", "ALIAS", "SYNONYM". 
5.REMARKS String => explanatory comment on the table 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

解决方案 »

  1.   

    具体可以这样使用
    getTables( null, null , aaa% or aaa_ or _aa% , TABLE or VIEW or SYSTEM TABLE or GLOBAL TEMPORARY or LOCAL TEMPORARY or ALIAS or SYNONYM )
                        throws SQLException其中有or 的地方根据需要选择一种情况。
      

  2.   

    To hui3zhihui (慧慧) :
    你还有什么困难吗?有的话,
    快点说吧!
      

  3.   

    tableNamePattern这个参数,我还是不大明白
      

  4.   

    这是原文:
    Some of these methods take arguments that are String patterns. These arguments all have names such as fooPattern. Within a pattern String, "%" means match any substring of 0 or more characters, and "_" means match any one character. Only metadata entries matching the search pattern are returned. If a search pattern argument is set to a null ref, that argument's criteria will be dropped from the search. 
    tableNamePattern  的使用方式如同统配附*,% 一样,%可以匹配任意个字符,而_只能匹配一个字符。当为aaa% 的时候,就是能匹配前三个字符为aaa的任意的表名。这样你可以得到你想要的满足要求的表名的一个子集!
    Good luck to u!
      

  5.   

    当我使用*的时候,出现的错误是 不合法的表达式
    当我定义了两个变量,来做参数传值的时候,出现getTables不能解析
      

  6.   

    sorry , String patterns are only two, one is '%' , the other is '_', so '*' is a illegal string patterns.我不清楚你的数据库有多少表,以及你想要那一部分的表,所以无法写具体代码,我想给你一点建议,就是多看看java api doc 。
    It's the whole world of Java.
      

  7.   

    These arguments all have names such as fooPattern.上面的话意思是string patterns 只能用在字符串的结尾处。
    所以我上面的_aa%是错误的。
      

  8.   

    getTables( null, null , null , null ) throws SQLException这样就可以了,但得到了所有类型的表。
    有如下类型的表:
    TABLE , VIEW , SYSTEM TABLE , GLOBAL TEMPORARY , LOCAL TEMPORARY , ALIAS ,SYNONYM
    没见过这么多的表吧,赫赫,实际上他们只是一种逻辑表示方式罢了,所以本质上是一样的。你也可以这样使用:
    getTables( null, null , null , TABLE ) throws SQLException
    这样你就得到表类型为TABLE 的全部表,我想后面的这个应该是你想用的!
      

  9.   

    To hui3zhihui (慧慧) :你看一下短消息,我刚才给你写了一段代码。
      

  10.   

    原贴内容:
    metadata.getTables()返回的结果集类型是TYPE_FORWARD_ONLY所以不行
    这个类型可以修改嘛??aaaaaaaaaaaaaaaaaaa
    不明白你说的-----返回的结果集类型是TYPE_FORWARD_ONLY。下面是api doc 中地原文:getTables
    public ResultSet getTables(String catalog,
                               String schemaPattern,
                               String tableNamePattern,
                               String[] types)
                        throws SQLException
    Returns:
    ResultSet - each row is a table description上面说返回ResultSet。我昨天说的注释掉rs后还有没有TYPE_FORWARD_ONLY这种问题呢?如果没有,那就是rs中得method使用有问题(next()之后可能previous()了)。其实最简单的方法,是你把代码发过来让我看看。
      

  11.   

    API我也看过很多次了,rs注释掉,就不会出现了,我也看得出来是rs的问题,就是说getTables()方法返回的ResultSet对象的类型问题。
      

  12.   

    如果得到结果以后,我不处理这个结果集的话,没有错误
    然后我使用System.out.println(rs.getString(1))
    输出的结果是我的数据库名