大家好我正在创建一个访问MySQL& amp; MsSQL数据库摆弄它们并依赖它访问的那些打印出来的表,这样做的代码部分是这样的:
Connection con = DriverManager.getConnection(dbUrl, userName,password);
Statement stmt = con.createStatement();
ResultSet rs;
if (driverCN.startsWith("com.mysql")) { // For MySQL.
rs = stmt.executeQuery("Show Tables");
} else { // For MsSQL
rs = stmt.executeQuery("??????");
}
// Displays the remaining Database tables.
System.out.println("\nThese are the remaining Database Tables:\n");
while (rs.next()) {
String db = rs.getString(1);
System.out.println(db);
}
现在我想知道的是,我如何为MsSQL做这个工作,我会执行什么样的查询并将结果传递给我的结果集? (这对MySQL数据库很有效,我只是没有MsSQL数据库来测试它。提前谢谢!
答案 0 :(得分:3)
SQL Server 2005或2008:
SELECT * FROM information_schema.tables
SQL Server 2000:
SELECT * FROM sysobjects WHERE xtype='U'
答案 1 :(得分:1)
尝试:
select name from sys.tables where type='u'