Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
DatabaseMetaData data = connection.getMetaData(); resultSet = data.getCatalogs(); while (resultSet.next()) { System.out.println(resultSet.getString("TABLE_CAT")); }
上面的代码给了我 sql server 的所有数据库的名称,但我只需要在 DSN 中配置的默认数据库
Statement statement = connection.createStatement(); ResultSet resultSet1 = statement.executeQuery("select db_name()"); while (resultSet1.next()) { System.out.println(resultSet1.getString(1)); }