Execute Update Return Generated Keys
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 following are Jave code examples for showing how to use getGeneratedKeys of the java.sql.Statement class. You can vote up the examples you like. Your votes will be used in our system to get more good examples. If it is an auto generated key, then you can use Statement#getGeneratedKeys for this. You need to call it on the same Statement as the one being used for the INSERT. You first need to create the statement using Statement.RETURNGENERATEDKEYS to notify the JDBC driver to return the keys.
Import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; public class Main. Dec 25, 2019 prepare-statement:return-keys may now be a vector of (auto-generated) column names to return, in addition to just being truthy or falsey. This allows keys to be returned for more databases. Officially support H2 (and test against it) to support JDBC-91 and clarify docstrings to improve debugging driver-specific restrictions on SQL. Executes the SQL statement in this PreparedStatement object, which may be any kind of SQL statement. Some prepared statements return multiple results; the execute method handles these complex statements as well as the simpler form of statements handled. Executes the given SQL statement, which may return multiple results, and signals the driver that the auto-generated keys indicated in the given array should be made available for retrieval. This array contains the names of the columns in the target table that contain the auto-generated keys.
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 upHave 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 •
解决办法:
|
The Microsoft JDBC Driver for SQL Server supports the optional JDBC 3.0 APIs to retrieve automatically generated row identifiers. 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.
Execute Update Return Generated Keys Download
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.
As an example, create the following table in the sample database:
Execute Update Return Generated Keys In Excel
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.