Execute Update Return Generated Keys

 admin
-->

The Microsoft JDBC Driver for SQL Server supports the optional JDBC 3.0 APIs to retrieve automatically generated row identifiers. Ms office 2010 professional plus product key generator download. The main value of this feature is to provide a way to make IDENTITY values available to an application that is updating a database table without a requiring a query and a second round-trip to the server.

Because SQL Server doesn't support pseudo columns for identifiers, updates that have to use the auto-generated key feature must operate against a table that contains an IDENTITY column. SQL Server allows only a single IDENTITY column per table. The result set that is returned by getGeneratedKeys method of the SQLServerStatement class will have only one column, with the returned column name of GENERATED_KEYS. If generated keys are requested on a table that has no IDENTITY column, the JDBC driver will return a null result set.

With the IBM® Data Server Driver for JDBC and SQLJ, you can use JDBC 3.0 methods to retrieve the keys that are automatically generated when you execute an INSERT statement. To retrieve automatically generated keys that are generated by an INSERT statement, you need to perform these steps. This array contains the names of the columns in the target table that contain the auto-generated keys that should be made available. The driver will ignore the array if the SQL statement is not an INSERT statement, or an SQL statement able to return auto-generated keys (the list of such statements is vendor-specific). Execute Update IStatement. A flag that indicates whether to allow retrieval of auto generated keys. /generate-an-encrypted-key-file-for-veracrypt.html. Parameter must be one of Statement.RETURNGENERATED. If generated keys are requested on a table that has no auto increment column, the JDBC driver will return a null result set. When you insert rows by executeUpdate or execute an INSERT statement or an INSERT within SELECT statement, you need to indicate that you will want to retrieve automatically generated key. Runs the given SQL statement, which can be an INSERT, UPDATE, DELETE, or MERGE statement; or an SQL statement that returns nothing, such as an SQL DDL statement. ExecuteUpdate (java.lang.String, int) Runs the given SQL statement and signals the Microsoft JDBC Driver for SQL Server with the given flag about whether the auto-generated keys. The driver will ignore the array if the SQL statement is not an INSERT statement, or an SQL statement able to return auto-generated keys (the list of such statements is vendor-specific). This method should be used when the returned row count may exceed Integer.MAXVALUE.

As an example, create the following table in the sample database:

In the following example, an open connection to the sample database is passed in to the function, an SQL statement is constructed that will add data to the table, and then the statement is run and the IDENTITY column value is displayed.

See also

Join GitHub today

GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.

Sign up New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comments

commented Jan 18, 2019

TX-LCN 5.0 使用 mybatis 和 mysql-connector-java 8.0.12 高版本导致无法分布式插入

commented Jan 18, 2019

Execute Update Return Generated Keys 2017

解决办法:

  1. <insert useGeneratedKeys='true'></insert> 标签使用 useGeneratedKeys 属性。
  2. 将 @TxcTransaction 注解改成 @LcnTransaction。

Execute Update Return Generated Keys 2016

closed this Feb 7, 2019
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment