0
     DatabaseMetaData data = connection.getMetaData();
     resultSet =  data.getCatalogs();
     while (resultSet.next()) {
      System.out.println(resultSet.getString("TABLE_CAT"));
    }

上面的代码给了我 sql server 的所有数据库的名称,但我只需要在 DSN 中配置的默认数据库

4

1 回答 1

1
Statement statement = connection.createStatement();
    ResultSet resultSet1 = statement.executeQuery("select db_name()");
    while (resultSet1.next()) {
        System.out.println(resultSet1.getString(1));
    }
于 2013-04-03T10:42:32.883 回答