Posts

Showing posts from June, 2021

ResultSet as Stream in Java

 Java ResultSet as Stream response   In this article I have tried to describe ResultSet as Stream and Rest API streaming response using java. Here I am using java9 to implement the solution. Let's start step by step implementation.   First let us discuss requirements or scenarios. 1. You need to provide stream response to the client, so that client can process the data using stream. 2. You need to fetch data by applying filters/criteria, but data size is so large. Hence cannot be keep it into the memory.    Following is tech stack I have used to solve the problem. 1.      SpringBoot 2.      Rest API 3.      H2 in-memory database 4.      Java 9   Step 1: Setup H2 database, add following properties in application.properties file. spring.datasource.url=jdbc:h2:mem:test spring.datasource.driverClassName=org.h2.Driver spring.datasource.username=sa spring.datasource.password= spring.jpa.database-platform=org.hibernate.dialect.H2Dialect   spring.h2.con