If your app thinks opening a new database connection for every request is clever then this tutorial is here to break that habit. We will walk through setting up JDBC connection pooling with HikariCP for Microsoft SQL Server and show how to stop starving your database and your users at the same time.
Use your build tool to include HikariCP and the Microsoft JDBC driver for SQL Server. If you use Spring Boot add the HikariCP starter so the framework wires things up for you. Do not commit sample URLs with credentials into a repo unless you enjoy explaining to your boss why production leaked secrets are cool.
Instantiate a HikariDataSource or declare it as a bean so the framework can manage its lifecycle. Set the basics like driverClassName, username, password, maximumPoolSize and connectionTimeout. The important part is to prefer a framework managed DataSource over a global singleton so shutdown and health checks actually behave.
Stop calling DriverManager directly. Obtain connections from the DataSource with getConnection. When you call close on that Connection you are returning it to the pool and not killing the underlying TCP link. That behavior is the whole point of connection pooling and also the reason your app will stop behaving like it is reinventing fire.
Start conservative with max pool size and min idle then observe actual throughput and latency. HikariCP exposes MBeans and can be integrated with Micrometer or Prometheus for metrics. Monitor connection usage, active connections, waiting threads and connection creation rates. If you see a lot of connection wait time you either need more pool capacity or you have long running queries that need fixing.
Run realistic load tests and measure latency and connection metrics. Look for connection leaks and threads waiting for connections. If the database shows slow queries fix them first. Increasing pool size is a band aid that hides problems and makes the database angrier.
In short, HikariCP plus a proper DataSource pattern gives you better resource use and faster responses with Microsoft SQL Server. Tune and monitor rather than guessing, and your app will thank you by not timing out the user who was only trying to click one button.
I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!
This is a dedicated watch page for a single video.