Nearby lessons

7 of 10

Spring Boot - Spring JDBC Application

📌 What You Will Learn
  • Understand Spring Boot - Spring JDBC Application
  • See working code examples
  • Learn from common mistakes and Q&A

Learn Spring Boot - Spring JDBC Application step by step — simple explanations, complete programs with their output, common beginner mistakes, and exam-style MCQs.

Spring Boot Application with Spring JDBC Application

------------------------------------------------------------------------

To prepare Spring Boot Application with Spring-JDBC , we have to use the following Steps.

  • Install Maven in our System:

a)Download Maven software from "http://maven.apache.org/download.cgi" url.

b)Unzip "apache-maven-3.6.2-bin.zip" file.

c)Set "path" environment variable to "C:\apache-maven-3.6.2\bin" either temporarily or

permanently.

set path=C:\apache-maven-3.6.2\bin;

  • Prepare ojdbc6 dependency manually:

Oracle Driver is a driver provided Oracle , it is licenced, it is not possible to get

dependency details manually, so we must prepare ojdbc6.jar dependency.

To prepare ojdbc6 dependency manually we have to use the following command on

Command prompt.

D:\>mvn install:install-file -

Dfile=C:\oraclexe\app\oracle\product\11.2.0\server\jdbc\lib\ojdbc6.jar -

DgroupId=com.oracle - DartifactId=ojdbc6 -Dversion=11.2.0 -Dpackaging=jar

For ojdbc6.jar file, we have to use the following dependency.

groupid: com.oracle

artifactid: ojdbc6

version:11.2.0

  • Prepare Spring boot Starter project in STS with Spring Web and JDBC API in SQL part.
  • Open pom.xml and add "ojdbc6" and tomcat-jasper:

Where ojdbc6.jar file is to interact with Oracle Database.

Where tomcat jasper is to provide JSPs support.

Spring Boot Application with Spring JDBC Application

server.port=1234

spring.mvc.view.prefix=/WEB-INF/

spring.mvc.view.suffix=.jsp

spring.datasource.driver-class-name=oracle.jdbc.OracleDriver

spring.datasource.url=jdbc:oracle:thin:@localhost:1521:xe

spring.datasource.username=system

spring.datasource.password=durga

Note: datasource name is not required, because, Spring boot is using Apache's "Hikary

Connection pooling Mechanism" bydefault.

  • Prepare "webapp/WEB-INF" folder under "src/main" folder.
  • Prepare all jsp pages under "src/main/webapp/WEB-INF" folder.
  • Prepare all Java Resources as per the structer.

EX:

----

application.properties:

------------------------------

server.port=1234

spring.mvc.view.prefix=/WEB-INF/

spring.mvc.view.suffix=.jsp

spring.datasource.driver-class-name=oracle.jdbc.OracleDriver

spring.datasource.url=jdbc:oracle:thin:@localhost:1521:xe

spring.datasource.username=system

spring.datasource.password=durga

welcome.jsp:

-----------------

Example02
JCode Cell
1 
2<project>
3----
4<dependencies>
5<dependency>
6<groupId>com.oracle</groupId>
7<artifactId>ojdbc6</artifactId>
8<version>11.2.0</version>
9</dependency>
10<dependency>
11<groupId>org.apache.tomcat</groupId>
12<artifactId>tomcat-jasper</artifactId>
13<version>9.0.26</version>
14</dependency>
15-----
16</dependencies>
17----
18</project>
19Provide the following details in application.properties file:
20

Spring Boot Application with Spring JDBC Application

//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

Example03
JCode Cell
1 
2<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
3pageEncoding="ISO-8859-1"%>
4<!DOCTYPE html PUBLIC "-
5

Spring Boot Application with Spring JDBC Application

10.<h1 style="color: red;" align="center">Durga Software Solutions</h1>

Example04
JCode Cell
1 
2<html>
3<head>
4<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
5<title>Insert title here</title>
6</head>
7<body>
8

Spring Boot Application with Spring JDBC Application

12.<table align="center" width="100%" height="100%">

Example05
JCode Cell
1 
2<hr>
3

Spring Boot Application with Spring JDBC Application

Addform.jsp

----------------

Example06
JCode Cell
1 
2<tr>
3<td align="center">
4<a href="addform">ADD Student</a>
5<a href="searchform">SEARCH Student</a>
6<a href="updateform">UPDATE Student</a>
7<a href="deleteform">DELETE Student</a>
8</td>
9</tr>
10</table>
11</body>
12</html>
13

Spring Boot Application with Spring JDBC Application

//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

Example07
JCode Cell
1 
2<%@ page <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
3pageEncoding="ISO-8859-1"%>
4<!DOCTYPE html PUBLIC "-
5

Spring Boot Application with Spring JDBC Application

10.<jsp:include page="/WEB-INF/welcome.jsp"/>

Example08
JCode Cell
1 
2<html>
3<head>
4<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
5<title>Insert title here</title>
6</head>
7<body>
8

Spring Boot Application with Spring JDBC Application

13.<form method="post" action="add">

14.<table align="center">

Example09
JCode Cell
1 
2<br><br><br><br><br>
3

Spring Boot Application with Spring JDBC Application

searchform.jsp:

-------------------

Example10
JCode Cell
1 
2<tr>
3<td>Student Id</td>
4<td><input type="text" name="sid"></td>
5</tr>
6<tr>
7<td>Student Name</td>
8<td><input type="text" name="sname"></td>
9</tr>
10<tr>
11<td>Student Address</td>
12<td><input type="text" name="saddr"></td>
13</tr>
14<tr>
15<td><input type="submit" value="ADD"/></td>
16</tr>
17</table>
18</form>
19</body>
20</html>
21

Spring Boot Application with Spring JDBC Application

//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

Example11
JCode Cell
1 
2<%<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
3pageEncoding="ISO-8859-1"%>
4<!DOCTYPE html PUBLIC "-
5

Spring Boot Application with Spring JDBC Application

10.<jsp:include page="/WEB-INF/welcome.jsp"/>

Example12
JCode Cell
1 
2<html>
3<head>
4<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
5<title>Insert title here</title>
6</head>
7<body>
8

Spring Boot Application with Spring JDBC Application

13.<form method="post" action="search">

14.<table align="center">

Example13
JCode Cell
1 
2<br><br><br><br><br>
3

Spring Boot Application with Spring JDBC Application

Example14
JCode Cell
1 
2<tr>
3<td>Student Id</td>
4<td><input type="text" name="sid"></td>
5</tr>
6

Spring Boot Application with Spring JDBC Application

updateform.jsp:

---------------------

Example15
JCode Cell
1 
2<tr>
3<td><input type="submit" value="SEARCH"/></td>
4</tr>
5</table>
6</form>
7</body>
8</html>
9

Spring Boot Application with Spring JDBC Application

//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

Example16
JCode Cell
1 
2<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
3pageEncoding="ISO-8859-1"%>
4<!DOCTYPE html PUBLIC "-
5

Spring Boot Application with Spring JDBC Application

10.<jsp:include page="/WEB-INF/welcome.jsp"/>

Example17
JCode Cell
1 
2<html>
3<head>
4<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
5<title>Insert title here</title>
6</head>
7<body>
8

Spring Boot Application with Spring JDBC Application

12.<form method="post" action="editform">

13.<table align="center">

Example18
JCode Cell
1 
2<br><br><br><br><br>
3

Spring Boot Application with Spring JDBC Application

Example19
JCode Cell
1 
2<tr>
3<td>Student Id</td>
4<td><input type="text" name="sid"></td>
5</tr>
6

Spring Boot Application with Spring JDBC Application

Editform.jsp

----------------

Example20
JCode Cell
1 
2<tr>
3<td><input type="submit" value="GetEditForm"/></td>
4</tr>
5</table>
6</form>
7</body>
8</html>
9

Spring Boot Application with Spring JDBC Application

//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

Example21
JCode Cell
1 
2<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
3pageEncoding="ISO-8859-1"%>
4<!DOCTYPE html PUBLIC "-
5

Spring Boot Application with Spring JDBC Application

10.<jsp:include page="/WEB-INF/welcome.jsp"/>

Example22
JCode Cell
1 
2<html>
3<head>
4<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
5<title>Insert title here</title>
6</head>
7<body>
8

Spring Boot Application with Spring JDBC Application

12.<form method="post" action="update">

13.<table align="center">

Example23
JCode Cell
1 
2<br><br><br><br><br>
3

Spring Boot Application with Spring JDBC Application

Example24
JCode Cell
1 
2<tr>
3<td>Student Id</td>
4<td>${std.sid}</td>
5</tr>
6<tr>
7<td>Student Name</td>
8<td><input type="text" name="sname" value="${std.sname}"></td>
9</tr>
10<tr>
11<td>Student Address</td>
12<td><input type="text" name="saddr" value="${std.saddr}"></td>
13</tr>
14<tr>
15<td><input type="submit" value="Update"></td>
16</tr>
17

Spring Boot Application with Spring JDBC Application

31.<input type="hidden" name="sid" value="${std.sid}">

Example25
JCode Cell
1 
2</table>
3

Spring Boot Application with Spring JDBC Application

//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

Example26
JCode Cell
1 
2</form>
3</body>
4</html>
5<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
6pageEncoding="ISO-8859-1"%>
7<!DOCTYPE html PUBLIC "-
8

Spring Boot Application with Spring JDBC Application

10.<jsp:include page="/WEB-INF/welcome.jsp"/>

Example27
JCode Cell
1 
2<html>
3<head>
4<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
5<title>Insert title here</title>
6</head>
7<body>
8

Spring Boot Application with Spring JDBC Application

13.<form method="post" action="delete">

14.<table align="center">

Example28
JCode Cell
1 
2<br><br><br><br><br>
3

Spring Boot Application with Spring JDBC Application

Example29
JCode Cell
1 
2<tr>
3<td>Student Id</td>
4<td><input type="text" name="sid"></td>
5</tr>
6

Spring Boot Application with Spring JDBC Application

studentdetails.jsp:

------------------------

Example30
JCode Cell
1 
2<tr>
3<td><input type="submit" value="DELETE"/></td>
4</tr>
5</table>
6</form>
7</body>
8</html>
9

Spring Boot Application with Spring JDBC Application

//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

Example31
JCode Cell
1 
2<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
3pageEncoding="ISO-8859-1"%>
4<!DOCTYPE html PUBLIC "-
5

Spring Boot Application with Spring JDBC Application

10.<jsp:include page="/WEB-INF/welcome.jsp"/>

Example32
JCode Cell
1 
2<html>
3<head>
4<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
5<title>Insert title here</title>
6</head>
7<body>
8

Spring Boot Application with Spring JDBC Application

12.<table align="center" border="1">

Example33
JCode Cell
1 
2<br><br><br><br><br>
3

Spring Boot Application with Spring JDBC Application

success.jsp:

---------------

Example34
JCode Cell
1 
2<tr>
3<td>Student Id</td>
4<td>${std.sid}</td>
5</tr>
6<tr>
7<td>Student Name</td>
8<td>${std.sname}</td>
9</tr>
10<tr>
11<td>Student Address</td>
12<td>${std.saddr}</td>
13</tr>
14</table>
15</body>
16</html>
17

Spring Boot Application with Spring JDBC Application

//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

Example35
JCode Cell
1 
2<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
3pageEncoding="ISO-8859-1"%>
4<!DOCTYPE html PUBLIC "-
5

Spring Boot Application with Spring JDBC Application

10.<jsp:include page="/WEB-INF/welcome.jsp"/>

Example36
JCode Cell
1 
2<html>
3<head>
4<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
5<title>Insert title here</title>
6</head>
7<body>
8

Spring Boot Application with Spring JDBC Application

12.<h1 style="color: red;" align="center">${operation} Success</h1>

Example37
JCode Cell
1 
2<br><br><br><br><br><br>
3

Spring Boot Application with Spring JDBC Application

failure.jsp

------------

Example38
JCode Cell
1 
2</body>
3</html>
4

Spring Boot Application with Spring JDBC Application

//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

Example39
JCode Cell
1 
2<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
3pageEncoding="ISO-8859-1"%>
4<!DOCTYPE html PUBLIC "-
5

Spring Boot Application with Spring JDBC Application

10.<jsp:include page="/WEB-INF/welcome.jsp"/>

Example40
JCode Cell
1 
2<html>
3<head>
4<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
5<title>Insert title here</title>
6</head>
7<body>
8

Spring Boot Application with Spring JDBC Application

12.<h1 style="color: red;" align="center">${operation} Failure</h1>

Example41
JCode Cell
1 
2<br><br><br><br><br><br>
3

Spring Boot Application with Spring JDBC Application

existed.jsp

-------------

Example42
JCode Cell
1 
2</body>
3</html>
4

Spring Boot Application with Spring JDBC Application

//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

Example43
JCode Cell
1 
2<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
3pageEncoding="ISO-8859-1"%>
4<!DOCTYPE html PUBLIC "-
5

Spring Boot Application with Spring JDBC Application

10.<jsp:include page="/WEB-INF/welcome.jsp"/>

Example44
JCode Cell
1 
2<html>
3<head>
4<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
5<title>Insert title here</title>
6</head>
7<body>
8

Spring Boot Application with Spring JDBC Application

12.<h1 style="color: red;" align="center">Student Existed Already</h1>

Example45
JCode Cell
1 
2<br><br><br><br><br><br>
3

Spring Boot Application with Spring JDBC Application

Notexisted.jsp

-------------------

Example46
JCode Cell
1 
2</body>
3</html>
4

Spring Boot Application with Spring JDBC Application

//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

Example47
JCode Cell
1 
2<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
3pageEncoding="ISO-8859-1"%>
4<!DOCTYPE html PUBLIC "-
5

Spring Boot Application with Spring JDBC Application

10.<jsp:include page="/WEB-INF/welcome.jsp"/>

Example48
JCode Cell
1 
2<html>
3<head>
4<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
5<title>Insert title here</title>
6</head>
7<body>
8

Spring Boot Application with Spring JDBC Application

12.<h1 style="color: red;" align="center">Student Not Existed</h1>

Example49
JCode Cell
1 
2<br><br><br><br><br><br>
3

Spring Boot Application with Spring JDBC Application

Example50
JCode Cell
1 
2</body>
3</html>
4

StudentController.java

------------------------------

StudentController.java

Example52
JCode Cell
1 
2package com.durgasoft.controller;
3

StudentController.java

10.import com.durgasoft.dto.Student;

11.import com.durgasoft.service.StudentService;

Example53
JCode Cell
1 
2import org.springframework.beans.factory.annotation.Autowired;
3import org.springframework.stereotype.Controller;
4import org.springframework.ui.ModelMap;
5import org.springframework.web.bind.annotation.RequestMapping;
6import org.springframework.web.bind.annotation.RequestMethod;
7import org.springframework.web.bind.annotation.RequestParam;
8

StudentController.java

14.public class StudentController {

Example54
JCode Cell
1 
2@Controller
3

StudentController.java

Example55
JCode Cell
1 
2@Autowired
3StudentService studentService;
4

StudentController.java

Example56
JCode Cell
1 
2@RequestMapping("/welcomepage")
3public String showWelcomePage() {
4return "welcome";
5}
6@RequestMapping("/addform")
7public String showAddPage() {
8return "addform";
9}
10@RequestMapping("/searchform")
11public String showSearchPage() {
12return "searchform";
13}
14@RequestMapping("/updateform")
15public String showUpdatePage() {
16return "updateform";
17}
18@RequestMapping("/editformform")
19public String showEditPage() {
20return "editform";
21}
22@RequestMapping("/deleteform")
23public String showDeletePage() {
24return "deleteform";
25}
26

StudentController.java

name,@RequestParam String saddr) {

Example57
JCode Cell
1 
2@RequestMapping(value="/add", method = RequestMethod.POST)
3public String add(ModelMap map, @RequestParam String sid, @RequestParam String s
4

StudentController.java

Example58
JCode Cell
1 
2map.addAttribute("operation", "Student Insertion");
3Student std = new Student();
4std.setSid(sid);
5std.setSname(sname);
6std.setSaddr(saddr);
7

StudentController.java

Example59
JCode Cell
1 
2String status = studentService.addStudent(std);
3

StudentController.java

Example60
JCode Cell
1 
2return status;
3}
4

StudentController.java

Example61
JCode Cell
1 
2@RequestMapping(value="/search", method=RequestMethod.POST)
3public String search(ModelMap map, @RequestParam String sid) {
4String status = "";
5Student std = studentService.searchStudent(sid);
6if(std == null) {
7status = "notexisted";
8}else {
9map.addAttribute("std", std);
10status = "studentdetails";
11}
12return status;
13}
14

StudentController.java

Example62
JCode Cell
1 
2@RequestMapping(value="editform", method = RequestMethod.POST)
3public String getEditForm(ModelMap map, @RequestParam String sid) {
4String status = "";
5Student std = studentService.searchStudent(sid);
6if(std == null) {
7status = "notexisted";
8}else {
9map.addAttribute("std", std);
10status="editform";
11}
12return status;
13}
14

StudentController.java

sname, @RequestParam String saddr) {

Example63
JCode Cell
1 
2@RequestMapping(value="update", method = RequestMethod.POST)
3public String update(ModelMap map,@RequestParam String sid, @RequestParam String
4

StudentController.java

Example64
JCode Cell
1 
2String status = "";
3map.addAttribute("operation", "Student Updation");
4Student std = new Student();
5std.setSid(sid);
6std.setSname(sname);
7std.setSaddr(saddr);
8

StudentController.java

Example65
JCode Cell
1 
2status = studentService.updateStudent(std);
3return status;
4}
5

StudentController.java

100.

101.map.addAttribute("operation", "Student Deletion");
102.String status = studentService.deleteStudent(sid);

return status;

}

}

Example66
JCode Cell
1 
2@RequestMapping(value = "delete", method = RequestMethod.POST)
3public String delete(ModelMap map, @RequestParam String sid) {
4

StudentService.java

---------------------------

StudentService.java

Example68
JCode Cell
1 
2package com.durgasoft.service;
3

StudentService.java

Example69
JCode Cell
1 
2import com.durgasoft.dto.Student;
3

StudentService.java

Example70
JCode Cell
1 
2public interface StudentService {
3public String addStudent(Student std);
4public Student searchStudent(String sid);
5public String updateStudent(Student std);
6public String deleteStudent(String sid);
7}
8

StudentServiceImpl.java

----------------------------------

StudentServiceImpl.java

Example72
JCode Cell
1 
2package com.durgasoft.service;
3

StudentServiceImpl.java

Example73
JCode Cell
1 
2import org.springframework.beans.factory.annotation.Autowired;
3import org.springframework.stereotype.Service;
4

StudentServiceImpl.java

Example74
JCode Cell
1 
2import com.durgasoft.dao.StudentDao;
3import com.durgasoft.dto.Student;
4

StudentServiceImpl.java

10.public class StudentServiceImpl implements StudentService {

Example75
JCode Cell
1 
2@Service
3

StudentServiceImpl.java

Example76
JCode Cell
1 
2@Autowired
3

StudentServiceImpl.java

Example77
JCode Cell
1 
2StudentDao studentDao;
3@Override
4public String addStudent(Student std) {
5

StudentServiceImpl.java

Example78
JCode Cell
1 
2String status = studentDao.add(std);
3return status;
4}
5

StudentServiceImpl.java

Example79
JCode Cell
1 
2@Override
3public Student searchStudent(String sid) {
4

StudentServiceImpl.java

Example80
JCode Cell
1 
2Student std = studentDao.search(sid);
3return std;
4}
5

StudentServiceImpl.java

Example81
JCode Cell
1 
2@Override
3public String updateStudent(Student std) {
4

StudentServiceImpl.java

Example82
JCode Cell
1 
2String status = studentDao.update(std);
3return status;
4}
5

StudentServiceImpl.java

String status = studentDao.delete(sid);

return status;

}

StudentDao.java

----------------------

package com.durgasoft.dao;

import com.durgasoft.dto.Student;

public interface StudentDao {

public String add(Student std);

public Student search(String sid);

public String update(Student std);

public String delete(String sid);

}

Example83
JCode Cell
1 
2@Override
3} public String deleteStudent(String sid) {
4

StudentDaoImpl.java

----------------------------

package com.durgasoft.dao;

StudentDaoImpl.java

Example85
JCode Cell
1 
2import java.util.List;
3

StudentDaoImpl.java

Example86
JCode Cell
1 
2import org.springframework.beans.factory.annotation.Autowired;
3import org.springframework.jdbc.core.JdbcTemplate;
4import org.springframework.stereotype.Repository;
5

StudentDaoImpl.java

Example87
JCode Cell
1 
2import com.durgasoft.dto.Student;
3

StudentDaoImpl.java

10.public class StudentDaoImpl implements StudentDao {

Example88
JCode Cell
1 
2@Repository
3

StudentDaoImpl.java

tSid()+"','"+std.getSname()+"','"+std.getSaddr()+"')");

Example89
JCode Cell
1 
2@Autowired
3JdbcTemplate jdbcTemplate;
4@Override
5public String add(Student std) {
6String status = "";
7Student student = search(std.getSid());
8if(student == null) {
9int rowCount = jdbcTemplate.update("insert into student values('"+std.ge
10

StudentDaoImpl.java

Example90
JCode Cell
1 
2if(rowCount ==1) {
3status = "success";
4}else {
5status = "failure";
6}
7}else {
8status = "existed";
9}
10return status;
11}
12

StudentDaoImpl.java

SID = '"+sid+"'", (rs, rowNum) ->{

Example91
JCode Cell
1 
2@Override
3public Student search(String sid) {
4Student std = null;
5List<Student> studentsList = jdbcTemplate.query("select * from student where
6

StudentDaoImpl.java

Example92
JCode Cell
1 
2Student s = new Student();
3s.setSid(rs.getString("SID"));
4s.setSname(rs.getString("SNAME"));
5s.setSaddr(rs.getString("SADDR"));
6return s;
7});
8if(studentsList.isEmpty() == true) {
9std = null;
10}else {
11std = studentsList.get(0);
12}
13return std;
14}
15

StudentDaoImpl.java

me()+"', SADDR = '"+std.getSaddr()+"' where SID = '"+std.getSid()+"'");

Example93
JCode Cell
1 
2@Override
3public String update(Student std) {
4String status = "";
5int rowCount = jdbcTemplate.update("update student set SNAME = '"+std.getSna
6

StudentDaoImpl.java

Example94
JCode Cell
1 
2if(rowCount == 1) {
3status = "success";
4}else {
5status = "failure";
6}
7return status;
8}
9

StudentDaoImpl.java

id+"'");

Example95
JCode Cell
1 
2@Override
3public String delete(String sid) {
4String status = "";
5Student std = search(sid);
6if(std == null) {
7status = "notexisted";
8}else {
9int rowCount = jdbcTemplate.update("delete from student where SID = '"+s
10

StudentDaoImpl.java

StudentApplication.java

---------------------------------

package com.durgasoft;

import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication

public class StudentappApplication {

public static void main(String[] args) {

SpringApplication.run(StudentappApplication.class, args);

}

}

pom.xml:

------------

Example96
JCode Cell
1 
2if(rowCount == 1) {
3status = "success";
4}else {
5status = "failure";
6}
7}
8return status;
9}
10}
11

StudentDaoImpl.java

sd/maven-4.0.0.xsd">

Example97
JCode Cell
1 
2<?xml version="1.0" encoding="UTF-8"?>
3<project xmlns="http://maven.apache.org/POM/4.0.0"
4xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/x
6

StudentDaoImpl.java

Example98
JCode Cell
1 
2<modelVersion>4.0.0</modelVersion>
3<parent>
4<groupId>org.springframework.boot</groupId>
5<artifactId>spring-boot-starter-parent</artifactId>
6<version>2.1.9.RELEASE</version>
7<relativePath /> <!-- lookup parent from repository -->
8</parent>
9<groupId>com.durgasoft</groupId>
10<artifactId>employee</artifactId>
11<version>0.0.1-SNAPSHOT</version>
12<name>employeeapp</name>
13<description>Spring boot employee app</description>
14

StudentDaoImpl.java

Example99
JCode Cell
1 
2<properties>
3<java.version>1.8</java.version>
4</properties>
5

StudentDaoImpl.java

Example100
JCode Cell
1 
2<dependencies>
3<dependency>
4<groupId>org.springframework.boot</groupId>
5<artifactId>spring-boot-starter-jdbc</artifactId>
6</dependency>
7<dependency>
8<groupId>com.oracle</groupId>
9<artifactId>ojdbc6</artifactId>
10<version>11.2.0</version>
11</dependency>
12<dependency>
13<groupId>org.apache.tomcat</groupId>
14<artifactId>tomcat-jasper</artifactId>
15<version>9.0.26</version>
16</dependency>
17

StudentDaoImpl.java

Example101
JCode Cell
1 
2<dependency>
3<groupId>org.springframework.boot</groupId>
4<artifactId>spring-boot-starter-web</artifactId>
5</dependency>
6

StudentDaoImpl.java

Example102
JCode Cell
1 
2<dependency>
3<groupId>org.springframework.boot</groupId>
4<artifactId>spring-boot-starter-test</artifactId>
5<scope>test</scope>
6</dependency>
7</dependencies>
8

StudentDaoImpl.java

Example103
JCode Cell
1 
2<build>
3<plugins>
4<plugin>
5<groupId>org.springframework.boot</groupId>
6<artifactId>spring-boot-maven-plugin</artifactId>
7</plugin>
8</plugins>
9</build>
10</project>
11
📝 Key Takeaways
  • Key ideas of Spring Boot - Spring JDBC Application explained simply
  • Ready-to-use code examples
  • Exam-style questions at the end