Categories
AWS Java SQL

Backup AWS MySQL, mount the backup locally and explore with SQuirreL

In this tutorial, we will backup an AWS RDS MySQL database as a dump, then we will mount the dump locally using a MySQL Testcontainers. Finally, we will explore the local backup content and schema, using SQuirreL. 1) Backup the AWS MySQL database We need an EC2 instance that has access to the database. For […]

Categories
AWS Bash Linux SQL

Connect MySQL client with private AWS RDS database, from EC2 instance

How to use the MySQL client command line interface with a private AWS RDS MySQL database. Let’s suppose we already have an EC2 instance, with an app that communicates with the database. For instance, the EC2 instance could be part of an Elastic Beanstalk environment (please see here how to setup a private AWS RDS […]

Categories
AWS SQL

Connect to AWS RDS MySQL from Elastic Beanstalk

In this article, we explain how to connect to a decoupled AWS RDS MySQL database from an AWS Elastic Beanstalk Docker environment. We will add the RDS security group to the Elastic Beanstalk environment. 1) Create the AWS RDS database Log into the AWS console, got to the RDS section, and click on the orange […]

Categories
Java SQL

Debug Java HikariCP Pool for JDBC SQL with Logback

In this article, we will explain how to use and debug HikariCP Pool for JDBC SQL with Logback. The goal is to be able to monitor how many connections are opened / closed by the connection pool. We will do a multi-thread load test of SQL requests on the pool, and see how it reacts. […]

Categories
Java SQL

JDBC Java transaction rollback demo with batch inserts

In this tutorial, we will see how JDBC Java transactions rollbacks are useful, with a real world example and a full Java demo. We will look at the particular case of batch inserts. 1) Batch inserts without rollback Let’s use the following SQL table: Starting from a JDBC connection object called conn: , the batch […]

Categories
Java SQL

Java JDBC batch inserts and performance test with PostgreSQL

In this tutorial, we will see how to batch SQL insert queries, using Java JDBC. Then, we will do a performance test to compare batched inserts VS non-batched inserts. 1) The SQL table We will use the following table: 2) Batch inserts Starting from a JDBC connection object called conn: simply do: We use the […]

Categories
Java SQL

Pretty print database SQL schema in Java using JDBC

How to pretty print a database SQL schema (table names, columns names and types), in Java using JDBC. Starting from a JDBC connection object to your database called conn: java.sql.Connection conn; simply do: The console output is the following: client ——————————————————————– id : uuid name : varchar product ——————————————————————– id : uuid name : varchar […]

Categories
Java SQL

Create a PostgreSQL index on a column and test performance with Java JDBC

In this tutorial we will see how to create an index on a SQL table column with JDBC, then we will fill a table with 10⁷ rows (using PostgreSQL fast COPY function), and finally we will compare the select performance with vs without the index. 1) The SQL tables and the index We will create […]

Categories
Java SQL

Real life useful example of an Inner Join with Java JDBC and PostgreSQL

In this tutorial we will run a full demo of a real life useful Inner Join, with Java JDBC and PostgreSQL. Let’s consider a recurring business that has Customers, Products to sell to customers and Subscriptions that give the list of products each customer has subscribed to. What we want to do is store all […]

Categories
Java SQL

Insert a Java object into a SQL table, with automatic mapping

In this tutorial, we will see a simple method to insert a Java object as a row into a SQL table. Thanks to Apache DB Utils and Apache Bean Utils, our mapping between Java JDBC and SQL will be automatic. 1) The Java object Let’s consider the following Java class Customer: (@AllArgsConstructor and @Data are annotations from the Lombok […]