DatabaseMetaData data = connection.getMetaData();
resultSet = data.getCatalogs();
while (resultSet.next()) {
System.out.println(resultSet.getString("TABLE_CAT"));
}
上面的代码给出了sql server的所有数据库的名称,但我只需要在DSN中配置的默认数据库
答案 0 :(得分:1)
Statement statement = connection.createStatement();
ResultSet resultSet1 = statement.executeQuery("select db_name()");
while (resultSet1.next()) {
System.out.println(resultSet1.getString(1));
}