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

Download an image directly with Selenium in Java

In this quick tutorial, we will explain how to download an image directly with Selenium in Java. The advantage of this method, instead of using a classic HTTP client like CURL, is that the website will behave exactly the same way as if you were browsing it with a classic browser like Chrome. 1) Setup […]

Categories
Java

Puppeteer Java and Playwright: how to scroll slowly to bottom of page

In this quick tutorial, we will see how to scroll slowly to the bottom of a web page, using Puppeteer Java and Playwright. Playwright is a new browser automation framework developed by Microsoft. It is based on JavaScript Puppeteer. Look here for a quick tutorial on how to use Playwright in Java. 1) Compute the […]

Categories
Java

Browser automation with Java equivalent of Puppeteer: Playwright

In this short tutorial, we will see how to do browser automation with a Java equivalent of JavaScript Puppeteer: a new framework developed by Microsoft called Playwright. 1) Import the dependency in your pom.xml In your pom.xml file, add: <dependency> <groupId>com.microsoft.playwright</groupId> <artifactId>playwright</artifactId> <version>1.15.2</version> </dependency> 2) Open Firefox and navigate to Wikipedia.com To open a Firefox […]

Categories
Docker Java

Run Java TestContainers using an image from a private AWS ECR registry

In this short tutorial, we will see how to easily run a private docker image using Java TestContainers. We will use a private AWS ECR registry, but the code will work the same with any other private registry. 1) Needed parameters First, you need to gather the following parameters: String registry = “601730646169.dkr.ecr.us-west-2.amazonaws.com”; String image […]

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

How to map and filter a list with Java lambda expressions

In this short tutorial, we will see how to map and filter a list with Java lambdas. 1) Map a list Let’s start from a list of integers: List<Integer> list = List.of(1, 3, 6, 2, 4, 5); To map the list, we need to convert it into a stream, then map it and finally collect […]

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 […]