共用方式為


getCatalogs Method (SQLServerDatabaseMetaData)

Retrieves the catalog names that are available in the connected server.

public java.sql.ResultSet getCatalogs()

傳回值

A SQLServerResultSet object.

例外狀況

SQLServerException

備註

This getCatalogs method is specified by the getCatalogs method in the java.sql.DatabaseMetaData interface.

The result set returned by the getCatalogs method will contain the following information:

Name Type Description

TABLE_CAT

String

The name of the catalog, including system databases in Microsoft SQL Server 2005.

範例

The following example demonstrates how to use the getCatalogs method to return the names of all the databases that are contained in Microsoft SQL Server 2005, including the system databases.

public static void executeGetCatalogs(Connection con) {
   try {
      DatabaseMetaData dbmd = con.getMetaData();
      ResultSet rs = dbmd.getCatalogs();
      ResultSetMetaData rsmd = rs.getMetaData();

      // Display the result set data.
      int cols = rsmd.getColumnCount();
      while(rs.next()) {
         for (int i = 1; i <= cols; i++) {
            System.out.println(rs.getString(i));
         }
      }
      rs.close();
   } 

   catch (Exception e) {
      e.printStackTrace();
   }
}

另請參閱

參考

SQLServerDatabaseMetaData Class

概念

SQLServerDatabaseMetaData Methods
SQLServerDatabaseMetaData Members