Below you will find pages that utilize the taxonomy term “springboot”
Spring
Retrieving Auto Generated Id With Spring JdbcTemplate
Introduction When developing database applications, one of the common requirements is to get the auto generated key back from the database after an insert statement has been executed. Different database vendors offer specific commands that can be used to retrieve auto generated keys, for example in MySQL, executing the following would obtain the last inserted key value.
SELECT LAST_INSERT_ID(); Using a GeneratedKeyHolder Spring’s JdbcTemplate uses a GeneratedKeyHolder class to return the last inserted generated key when executing update commands via PreparedStatements.
Spring
Accessing Multiple Databases From A SpringBoot Application
Introduction When developing any application, it’s quite common to have to access multiple databases. Out of the box, Spring Boot provides easy access to a single datasource, in the simplest case just by specifying the JDBC driver on the class path!
Accessing multiple databases however, is still straightforward with Spring Boot. This article shows how to connect to two different MySql datasources from a Spring Boot application.
Database Schema To showcase how to connect to to different databases, consider a products database and a customer database, with the following simplistic schema and data.