logo
down
shadow

Is there anyway to get the generated keys when using Spring JDBC batchUpdate?


Is there anyway to get the generated keys when using Spring JDBC batchUpdate?

By : djfrancox
Date : October 28 2020, 04:55 PM
around this issue Spring framework folks attempted a solution to this problem. But they abandoned the attempt when it became apparent that there is no way to guarantee that the solution will work with all JDBC Drivers. This is because the JDBC spec doesn't guarantee that the generated keys will be made available after a batch update. JDBC drivers are free to implement this feature as they see fit. In some cases the underlying database might not return the generated keys making it impossible for the driver to support this feature.
So even if you are directly working with JDBC, you will need to check whether your database and JDBC driver makes the generated keys available.
code :


Share : facebook icon twitter icon
Sybase JDBC get generated keys

Sybase JDBC get generated keys


By : Andre Watts
Date : March 29 2020, 07:55 AM
I wish this help you In Postgres, I can write , My current implementation executes three consecutive SQL statements:
code :
-- insert the data first
INSERT INTO .. VALUES (..)

-- get the generated identity value immediately afterwards
SELECT @@identity

-- get the remaining values from the record (possibly generated by a trigger)
SELECT * FROM .. WHERE ID = :previous_identity
Retrieving customized auto-generated keys with Spring JDBC Template

Retrieving customized auto-generated keys with Spring JDBC Template


By : ZhenLei
Date : March 29 2020, 07:55 AM
it helps some times I am required to retrieve customized auto-generated key using spring jdbc template after insertion of a record. , Here is the solution, instead of using
code :
String creditId = keyHolder.getKey().toString();
String creditId = (String) keyHolder.getKeys().get("CREDITID");
How to obtain the generated keys when using the NamedParameterJDBCTemplate in a batchUpdate

How to obtain the generated keys when using the NamedParameterJDBCTemplate in a batchUpdate


By : limeni
Date : March 29 2020, 07:55 AM
Hope this helps It's possible by extending JdbcTemplate and adding a method which is an exact copy of batchUpdate method and take an extra param of Type KeyHolder, there in PreparedStatementCallback after ps.executeBatch() you should call ResultSet keys = ps.getGeneratedKeys() and extract the generated keys and store theme in KeyHolder but there is no guarantee that ps.getGeneratedKeys() will return value it depends on database
Spring-jdbc 5.0.5 NamedParameterJdbcTemplate.batchUpdate ORA-01000

Spring-jdbc 5.0.5 NamedParameterJdbcTemplate.batchUpdate ORA-01000


By : shlomit
Date : March 29 2020, 07:55 AM
seems to work fine After migrating from Spring 4.1.7 to Spring 5.0.5 we have ORA-01000: maximum open cursors exceeded when using with Oracle 12c and ojdbc7 driver , Juergen Hoeller:
Spring-JDBC batchUpdate is not committing changes. Is this a knwon bug?

Spring-JDBC batchUpdate is not committing changes. Is this a knwon bug?


By : avy
Date : March 29 2020, 07:55 AM
I wish did fix the issue. If you do not want to use autocommit, you have to setup a PlatformTransactionManager in your Spring configuration. For simple JDBC usage, you can use a DataSourceTransationManager.
In web application, it is common to use @Transactional annotations in service layer. In a simple application, Spring proposes the TransactionTemplate. Here is an example from Spring Reference Manual 3.2
Related Posts Related Posts :
  • Is O(N!*N) an acceptable big oh complexity class or do I remove the constant and just say O(N!)?
  • Java File URI error?
  • Using an interface as a constructor parameter in Java?
  • Add additional path to exec-maven-plugin
  • Natural Language parsing of an appointment?
  • Java: How to tell which fontconfig file my system is currently using?
  • How to create notification icon badge on Android apps (like iPhone)
  • Interfaces with hibernate annotations
  • Getting ConnectionTimeoutException with the host did not accept the connection within timeout
  • How to get all property names of a Groovy class?
  • Java Netscape LDAP Remove One Attribute
  • A simple two column layout with Swing
  • Making a Linked list using Generics
  • how to handle result set data
  • Cloning java ArrayList and preventing it from modifications
  • Java How to call method of grand parents?
  • running jython bytecode using java
  • get content from website with utf8 format
  • Sendgrid v3: "Substitutions may not be used with dynamic templating"
  • Application freezes when running method
  • Maven versioning using git branches
  • does a Java getter incur a performance penalty
  • Open Source Implementation of Checkers
  • How can I make a resizable array in Java?
  • Change size of ImageIcon in a JRadioButton
  • Java memory mapped files and swap
  • JAXB Annotated class - setting of a variable which is not an element
  • JSF don't find component in view root with the form id
  • Using Mockito, how do I match against the key-value pair of a map?
  • How do I run my application as superuser from Eclipse?
  • Spring-Security: Call method after authentication
  • How can I add a password to this JDBC:ODBC connection string that is trying to connect to an MS Access database
  • java.sql.SQLException: database locked
  • Json Jackson deserialization without inner classes
  • Error starting modern compiler
  • Generate a random number in interval [0,360) which is divisible by number 15
  • Rotate watermark text at 45 degree angle across the center Apache PDFBox
  • Generate Random number in a range with no repeatation
  • Starting HBASE, java.lang.ClassNotFoundException: org.apache.htrace.SamplerBuilder
  • Using getter and setter methods inside a class in my main class
  • java: <identifier> expected with ArrayList
  • Java Reflection, java.lang.IllegalAccessException Error
  • Looking for a lightweight java-compatible in-memory key-value store
  • What is your development checklist for Java low-latency application?
  • Read a line in java and then tokenize it
  • How to format a date using Apache Derby?
  • Explicitly multiplying values as longs
  • Starting out NLP - Python + large data set
  • Software Testing Tools - for java
  • JDBC transaction dead-lock: solution required?
  • Measuring the time to create and destroy a simple object
  • Javadoc error: "option --boot-class-path not allowed with target 11"
  • How can I store values in a hashmap with <String, List<Integer>>
  • JDBC ODBC.. (Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException)
  • Unable to detect Capture Device (webcam) through JMF
  • Audio fingerprinting library (java)
  • Help matching fields between two classes
  • Access variables between nested JSP tags
  • AES Encryption Java Invalid Key length
  • How to initiate chatting between two clients and two clients only, using applets and servlets?
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk