Managing Result Sets with the JDBC Driver

DownloadDownload JDBC Driver

The result set is an object that represents a set of data returned from a data source, usually as the result of a query. The result set contains rows and columns to hold the requested data elements, and it is navigated with a cursor. A result set can be updatable, meaning that it can be modified and have those modifications pushed to the original data source. A result set can also have various levels of sensitivity to changes in the underlying data source.

The type of result set is determined when a statement is created, which is when a call to the createStatement method of the SQLServerConnection class is made. The fundamental role of a result set is to provide Java applications with a usable representation of the database data. This is typically done with the typed getter and setter methods on the result set data elements.

In the following example, which is based on the AdventureWorks sample database, a result set is created by calling the executeQuery method of the SQLServerStatement class. Data from the result set is then displayed by using the getString method of the SQLServerResultSet class.

public static void executeStatement(Connection con) {
   try {
      String SQL = "SELECT TOP 10 * FROM Person.Contact";
      Statement stmt = con.createStatement();
      ResultSet rs = stmt.executeQuery(SQL);

      while ( {
         System.out.println(rs.getString(4) + " " + rs.getString(6));
   catch (Exception e) {

The topics in this section describe various aspects of result set usage, including cursor types, concurrency, and row locking.

In This Section

Topic Description
Understanding Cursor Types Describes the different cursor types that the Microsoft JDBC Driver for SQL Server supports.
Understanding Concurrency Control Describes how the JDBC driver supports concurrency control.
Understanding Row Locking Describes how the JDBC driver supports row locking.

See Also

Overview of the JDBC Driver