Posts

Showing posts with the label Multiple Datasources

Spring Boot, MyBatis Multiple Datasources Example

Image
In this section, we will show you  how we can use multiple data sources in Spring Boot, MyBatis application. In this example we will create two data source configurations for User DB(PostgreSQL) and Student DB(MySQL).  Technologies used: Spring Boot 3.0.2 MyBatis 3 Java 17 Maven  PostgreSQL driver and database MySQL driver and database Database setup PostgreSQL - Create database and table. Create a database in the PostgreSQL.   CREATE DATABASE userdb; Then, create table users.  CREATE TABLE IF NOT EXISTS public.users (     id           serial primary key ,     email         VARCHAR ( 40 ) not null ,     first_name   VARCHAR ( 40 ) not null ,     last_name     VARCHAR ( 40 ) not null ); MySQL - Create database and table. Create a database in the MySQL.   CREATE DATABASE studentdb; Then, create table students.  CREATE TABLE IF NOT EXISTS stude...