Posts

Showing posts with the label JDBC

#3 Passing Query Paramater In REST API

Image
Please go through series 1 and series 2 before starting this tutorial. In my last tutorials I have explained that how can we create simple hello world API and how can we access DB by using JDBCTemplate . JDBCTemplate is spring framework's library which make easy to access the DB. So now let me continue to the topic. Lets extends EmployeeDao to another method which will fetch Employee data based on email id passed. Please see the example below: Please note that I have added another method with email parameter. Now lets implement this method in interface implementation class ( named as EmployeeDaoImpl ): Now lets write REST api to access employee data with email passed. Write following method in your Controller class: We write another REST api names getemployee with request parameter email.  I have used  @RequestParam for parameter. You can make parameter as required OR optional . Now to access api you can call rest url as given below, by p...

#2 Simple Spring Rest Api with JDBC connection

Image
Before starting this tutorial, I am assuming that you guys have basic idea of Spring. If you don't have basic idea of simple Spring API then no worry :), I have written simple tutorial here to start with Spring Boot . This tutorial is next version of my first tutorial . In my first tutorial I explained that how can we make a simple REST api with Spring Boot .  So lets start with JDBC connection in some very simple steps: 1. Create DB schema and table I prefer MySqlWorkBench for this purpose ( you can use any way to create schema). For this tutorial I have named my db as test_db . This DB contains one Employee table with below schema: Table contains id, name and email of employee ( This is just for tutorial, You make table as per your requirement). Once you created table, Insert some dummy data for your REST api. Your api will be fetching this data and will return it as JSON. I have made some of dummy entries as below: 2. Add Maven depen...