Skip to content

Latest commit

 

History

History
33 lines (24 loc) · 2.53 KB

File metadata and controls

33 lines (24 loc) · 2.53 KB
title Using a SQL statement to modify data
description Using a SQL statement to modify data
author David-Engel
ms.author davidengel
ms.date 08/12/2019
ms.service sql
ms.subservice connectivity
ms.topic conceptual

Using a SQL statement to modify data

[!INCLUDEDriver_JDBC_Download]

To modify the data that is contained in a [!INCLUDEssNoVersion] database by using a SQL statement, you can use the executeUpdate method of the SQLServerStatement class. The executeUpdate method will pass the SQL statement to the database for processing, and then return a value that indicates the number of rows that were affected.

To do this, you must first create a SQLServerStatement object by using the createStatement method of the SQLServerConnection class.

In the following example, an open connection to the [!INCLUDEssSampleDBnormal] sample database is passed in to the function, a SQL statement is constructed that adds new data to the table, and then the statement is run and the return value is displayed.

[!codeJDBC#UsingSQLToModifyData1]

Note

If you must use a SQL statement that contains parameters to modify the data in a [!INCLUDEssNoVersion] database, you should use the executeUpdate method of the SQLServerPreparedStatement class.

If the column that you are trying to insert data into contains special characters such as spaces, you must provide the values to be inserted, even if they are default values. If you do not, the insert operation will fail.

If you want the JDBC driver to return all update counts, including update counts returned by any triggers that may have fired, set the lastUpdateCount connection string property to "false". For more information about the lastUpdateCount property, see Setting the connection properties.

See also

Using statements with SQL