一.Java方法
// 得到当前数据库下所有的表名
--MySQL数据库
转自:http://hi.baidu.com/rybwxn/blog/item/1a59502a75a7de25d52af1cc.html
// 得到当前数据库下所有的表名
public void getTableNameByCon(Connection con) {
try {
DatabaseMetaData meta = con.getMetaData();
ResultSet rs = meta.getTables(null, null, null,
new String[] { "TABLE" });
while (rs.next()) {
System.out.println("表名:" + rs.getString(3));
System.out.println("表所属用户名:" + rs.getString(2));
System.out.println("------------------------------");
}
con.close();
} catch (Exception e) {
try {
con.close();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
// TODO Auto-generated catch block
e.printStackTrace();
}
}二.通过sql语句得到数据库里所有的表名--MySQL数据库
show tables;--Oracle数据库(当前登录用户下的表)select uo.object_name from user_objects uo where uo.object_type = 'TABLE';--sql server 2000/2005数据库select name from sysobjects--sybase数据库select name from sysobjects where type='U';--DB2数据库 select tabname from syscat.tables where tabschema = current schema ;// 获取当前模式下面的所有用户表转自:http://hi.baidu.com/rybwxn/blog/item/1a59502a75a7de25d52af1cc.html
本文介绍了在不同数据库环境下获取所有表名的方法,包括MySQL、Oracle、SQL Server、Sybase和DB2等,提供了SQL语句和Java代码实现。
3600

被折叠的 条评论
为什么被折叠?



