类: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
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
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 的地方根据需要选择一种情况。
你还有什么困难吗?有的话,
快点说吧!
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!
当我定义了两个变量,来做参数传值的时候,出现getTables不能解析
It's the whole world of Java.
所以我上面的_aa%是错误的。
有如下类型的表:
TABLE , VIEW , SYSTEM TABLE , GLOBAL TEMPORARY , LOCAL TEMPORARY , ALIAS ,SYNONYM
没见过这么多的表吧,赫赫,实际上他们只是一种逻辑表示方式罢了,所以本质上是一样的。你也可以这样使用:
getTables( null, null , null , TABLE ) throws SQLException
这样你就得到表类型为TABLE 的全部表,我想后面的这个应该是你想用的!
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()了)。其实最简单的方法,是你把代码发过来让我看看。
然后我使用System.out.println(rs.getString(1))
输出的结果是我的数据库名