java如何获取数据库中所有表名
2个回答
2018-06-06
展开全部
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));
}
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();
}
}
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));
}
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();
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询