Posts

Test Driven Development - As a Beginner

Image
  My Journey with Test-Driven Development Many years ago, when I started working on a new project, my Architect & the head of the Project wanted us to follow Test Driven Development (TDD) approach. That was the first time I heard about this concept. As with any other developer even I was in the mindset that writing a test first is not going to work and is very time-consuming. But, I wanted to give it a try. I started by writing a test for a simple method that I needed to implement in my code. Here's an example of the test that I started playing with TDD: public void testAddition () {      Calculator calculator = new Calculator ();      int result = calculator.add( 2 , 3 );      assertEquals( 5 , result); } This test checks that the add method of the Calculator class correctly adds two numbers together. The assertEquals method checks that the result is equal to the expected value, which is 5 i...

Export data from MySQL to CSV file

Image
Export Data from MySQL using Hikari Datasource Objective Exporting data from a MySQL table to a CSV file can also be done programmatically using Java and a JDBC driver for MySQL such as the Hikari Datasource. In this blog post, I will show you how to use Hikari Datasource and Java to export data from a MySQL table to a CSV file. Step 1: Set up Hikari Datasource The first step is to set up Hikari Datasource in your Java project. You can add the HikariCP dependency to your project's build file or use your preferred build automation tool like Gradle or Maven. After that, you can create a HikariConfig object and set the necessary properties for connecting to your MySQL server, such as the server URL, username, and password. Here's an example of setting up a Hikari Datasource object: HikariConfig config = new HikariConfig (); config. setJdbcUrl ( "jdbc:mysql://localhost:3306/mydatabase" ); config. setUsername ( "myusername" ); config. setPassword ( "mypass...