Events
Mar 31, 11 PM - Apr 2, 11 PM
The biggest SQL, Fabric and Power BI learning event. March 31 – April 2. Use code FABINSIDER to save $400.
Register todayThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
To query a result set for information about the columns that it contains, the Microsoft JDBC Driver for SQL Server implements the SQLServerResultSetMetaData class. This class contains numerous methods that return information in the form of a single value.
To create a SQLServerResultSetMetaData object, you can use the getMetaData method of the SQLServerResultSet class.
In the following example, an open connection to the AdventureWorks2022 sample database is passed in to the function, the getMetaData method of the SQLServerResultSet class is used to return a SQLServerResultSetMetaData object, and then various methods of the SQLServerResultSetMetaData object are used to display information about the name and data type of the columns contained within the result set.
public static void getResultSetMetaData(Connection con) {
try(Statement stmt = con.createStatement();) {
String SQL = "SELECT TOP 10 * FROM Person.Contact";
ResultSet rs = stmt.executeQuery(SQL);
ResultSetMetaData rsmd = rs.getMetaData();
// Display the column name and type.
int cols = rsmd.getColumnCount();
for (int i = 1; i <= cols; i++) {
System.out.println("NAME: " + rsmd.getColumnName(i) + " " + "TYPE: " + rsmd.getColumnTypeName(i));
}
}
// Handle any errors that may have occurred.
catch (SQLException e) {
e.printStackTrace();
}
}
Events
Mar 31, 11 PM - Apr 2, 11 PM
The biggest SQL, Fabric and Power BI learning event. March 31 – April 2. Use code FABINSIDER to save $400.
Register todayTraining
Module
Use system catalogs and system views in PostgreSQL - Training
Relational databases can store vast quantities of data, but they also need to hold information about the structure of that data. For an operational database management system (DBMS) information about the structure of tables, and all other objects, security, and concurrency, amongst many other settings and metrics, is required. This information is know as metadata and is stored in system catalogs in Azure Database for PostgreSQL. In addition to directly accessing system catalogs, you can access system views
Documentation
Using multiple result sets - JDBC Driver for SQL Server
Learn how to query and retrieve multiple result sets from a single execute using the JDBC Driver for SQL Server.
Using parameter metadata - JDBC Driver for SQL Server
Using parameter metadata
getServerName Method (SQLServerDataSource) - JDBC Driver for SQL Server
getServerName Method (SQLServerDataSource)