Hello guys, If you have been using the Spring framework then you may know that the JdbcTempalte is one of the most useful classes of Spring framework. The JdbcTempalte class provides lots of convenient methods for performing database-related tasks that take the pain away from using the JDBC API. If you have worked in any real-life JAva project which connects to Database ...
Read More »Home »
Tomcat JDBC Pool – Connection Leak – Catch the Culprit
Database connection leaks are something that can stay hidden unless paid specific attention and would come to the surface at the most critical stages at a peak time of the system. We would manually check if all the open connections have been closed properly. Then we have various code quality plugins that would scan and check for that. Still when ...
Read More »Spring Boot and Micrometer with InlfuxDB Part 3: Servlets and JDBC
In the previous blog we setup a reactive application with micrometer backed with an InfluxDB. On this tutorial we shall use our old school blocking Servlet Based Spring Stack with JDBC. My database of choice would be postgresql. I shall use the same scripts of a previous blog post. Thus we shall have the script that initializes the database 01 ...
Read More »Read replicas and Spring Data Part 4: Configuring the read repository
Previously we set up two EntityManagers in the same application. One for the reads and one for the writes. Now it’s time to create our read repository. The read only repository will use the secondary read only EntityManager. In order to make it a read only repository, it is essential not to have any save and persist actions. 01 02 ...
Read More »Read replicas and Spring Data Part 3: Configuring two entity managers
Our previous setup works as expected. What we shall do now is to get one step further and configure two separate entity managers without affecting the functionality we achieved previously. The first step would be to set the default entity manager configuration to a primary one.This is the first step 01 02 03 04 05 06 07 08 09 10 ...
Read More »Read replicas and Spring Data Part 2: Configuring the base project
In our previous post we set up multiple PostgreSQL instances with the same data.Our next step would be to configure our spring project by using the both servers. As stated previously we shall use some of the code taken from the Spring Boot JPA post, since we use exactly the same database. This shall be our gradle build file 01 ...
Read More »Read replicas and Spring Data Part 1: Configuring the Databases
This is a series of blog posts on our quest to increase our application’s performance by utilizing read replicas. For this project our goal is to set up our spring data application and use read repositories for writes and repositories based on read replicas for reads. In order to simulate this environment we shall use PostgreSQL instances through Docker. The ...
Read More »JDBC – Emulating a sequence
Probably each of us encountered this problem at least once in the programmer’s life – how to emulate a database sequence? Below you may find my variation of this problem’s solution. Suppose that we have an interface defining the desired API for returning a sequence of integer numbers: 1 2 3 4 5 public interface Sequences { int nextValue(String ...
Read More »Java: Streaming a JDBC ResultSet as CSV
In my previous post, I showed how to convert a java.sql.ResultSet to JSON and stream it back to the caller. This post, is about streaming it in CSV format instead. Streaming allows you to transfer the data, little by little, without having to load it all into the server’s memory. For example, consider the following ResultSet: +---------+-----+ | Name | ...
Read More »