| title | Reading large data with stored procedures sample |
|---|---|
| description | This JDBC Driver sample demonstrates how to retrieve a large OUT parameter from a stored procedure. |
| author | David-Engel |
| ms.author | davidengel |
| ms.date | 04/20/2021 |
| ms.service | sql |
| ms.subservice | connectivity |
| ms.topic | sample |
[!INCLUDEDriver_JDBC_Download]
This [!INCLUDEjdbcNoVersion] sample application demonstrates how to retrieve a large OUT parameter from a stored procedure.
The code file for this sample is named ExecuteStoredProcedure.java, and can be found in the following location:
\<installation directory>\sqljdbc_<version>\<language>\samples\adaptiveTo run this sample application, you'll need access to the [!INCLUDEssSampleDBnormal] sample database. Set the classpath to include the mssql-jdbc jar file. For more information about how to set the classpath, see Using the JDBC Driver.
Note
The [!INCLUDEjdbcNoVersion] provides mssql-jdbc class library files to be used depending on your preferred Java Runtime Environment (JRE) settings. For more information about which JAR file to choose, see System Requirements for the JDBC Driver.
The sample would create the required stored procedure in the [!INCLUDEssSampleDBnormal] sample database:
This sample code:
- Makes a connection to the [!INCLUDEssSampleDBnormal] database.
- Creates sample data and updates the
Production.Documenttable by using a parameterized query. Finally, the sample code gets the adaptive buffering mode by using the getResponseBuffering method of the SQLServerStatement class and executes theGetLargeDataValuestored procedure. Starting with the JDBC driver version 2.0 release, theresponseBufferingconnection property is set to "adaptive" by default.
Finally, the sample code displays the data returned with the OUT parameters and also demonstrates how to use the mark and reset methods on the stream to re-read any portion of the data.
:::code language="java" source="codesnippet/Java/reading-large-data-with-_1_1.java":::