求助关于取得数据库所有表名的方法

wpz0k 2003-09-29 11:38:19
首先我用的是ibm cloudscape 5.1.20(60天试用),想用某种方法取得某库下所用表的表名,请高手指点,谢谢。
...全文
20 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
zihuilegend 2003-09-29
  • 打赏
  • 举报
回复
try {
Connection conn = Conn.getConnection();//获得你自己的数据库连接
Statement stmt = conn.createStatement();
String sql = "select * from tab";
System.out.println(sql);
ResultSet RS = stmt.executeQuery(sql);
while (RS.next() ) {
out.println(RS.getString(1)+"<br>");
}
stmt.close();
conn.close();
}
catch (Exception ex) {
System.out.println("First part's Error: "+ex.toString() );
}
zihuilegend 2003-09-29
  • 打赏
  • 举报
回复
try {
Connection conn = Conn.getConnection(); //获得你自己的连接
Statement stmt = conn.createStatement();
String sql = "select * from tab";
System.out.println(sql);
ResultSet RS = stmt.executeQuery(sql);
while (RS.next() ) {
out.println(RS.getString(1)+"<br>");
}
stmt.close();
conn.close();
}
catch (Exception ex) {
System.out.println("First part's Error: "+ex.toString() );
}
cowboy1114 2003-09-29
  • 打赏
  • 举报
回复
我只知道在Oracle中获得所有表名的方法为
select * from tab;
你试试看
wpz0k 2003-09-29
  • 打赏
  • 举报
回复
cowboy1114(傻牛)的方法行不通,
zihuilegend(子辉)(愚昧无知) 的方法行不通,
teaky2002(种田硬手) 的方法我查过javadoc,可行。
liad() ( )的方法可行,不过不是用ibm ij 工具。
ChDw(米) 的方法和teaky2002(种田硬手)一样。

谢谢大家的支持。
ChDw 2003-09-29
  • 打赏
  • 举报
回复
不应该通过select语句去做,而是应该采用
conn.getMetaData().getTables(conn.getCatalog(),"%","%",new String[]{"TABLE","VIEW"});
liad 2003-09-29
  • 打赏
  • 举报
回复
http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/Tools4.html

This command lists the names of all user tables in the database:

ij> select tablename from sys.systables
where tabletype = 'T';

teaky2002 2003-09-29
  • 打赏
  • 举报
回复
java.sql
Interface DatabaseMetaData


getTables() 方法
public ResultSet getTables(String catalog,
String schemaPattern,
String tableNamePattern,
String[] types)
throws SQLException


这个是java中自带的类,如果能连接上数据库,都可以通用。
okwuzhijun 2003-09-29
  • 打赏
  • 举报
回复
我只知道oracle两种方法:
select table_name from user_tables;
select * from tab;
建议里的数据库版去问问。

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧