title | description | author | ms.author | ms.date | ms.service | ms.subservice | ms.topic | apilocation | apiname | apitype |
---|---|---|---|---|---|---|---|---|---|---|
getCatalogs Method (SQLServerDatabaseMetaData) |
getCatalogs Method (SQLServerDatabaseMetaData) |
David-Engel |
davidengel |
01/19/2017 |
sql |
connectivity |
reference |
sqljdbc.jar |
SQLServerDatabaseMetaData.getCatalogs |
Assembly |
[!INCLUDEDriver_JDBC_Download]
Retrieves the catalog names that are available in the connected server.
public java.sql.ResultSet getCatalogs()
A SQLServerResultSet object.
This getCatalogs method is specified by the getCatalogs method in the java.sql.DatabaseMetaData interface.
Note
On Azure SQL Database, you should connect to the master
database to call SQLServerDatabaseMetaData.getCatalogs. SQL Database does not support returning the entire set of catalogs from a user database. SQLServerDatabaseMetaData.getCatalogs uses the sys.databases
view to get the catalogs.
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 [!INCLUDEmsCoName] [!INCLUDEssNoVersion]. |
The following example demonstrates how to use the getCatalogs method to return the names of all the databases that are contained in [!INCLUDEmsCoName] [!INCLUDEssNoVersion], 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 Methods
SQLServerDatabaseMetaData Members
SQLServerDatabaseMetaData Class