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
Loading editor…

Spring Boot Application with Spring JDBC Application

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

Example03
Loading editor…

Spring Boot Application with Spring JDBC Application

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

Example04
Loading editor…

Spring Boot Application with Spring JDBC Application

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

Example05
Loading editor…

Spring Boot Application with Spring JDBC Application

Addform.jsp

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

Example06
Loading editor…

Spring Boot Application with Spring JDBC Application

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

Example07
Loading editor…

Spring Boot Application with Spring JDBC Application

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

Example08
Loading editor…

Spring Boot Application with Spring JDBC Application

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

14.<table align="center">

Example09
Loading editor…

Spring Boot Application with Spring JDBC Application

searchform.jsp:

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

Example10
Loading editor…

Spring Boot Application with Spring JDBC Application

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

Example11
Loading editor…

Spring Boot Application with Spring JDBC Application

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

Example12
Loading editor…

Spring Boot Application with Spring JDBC Application

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

14.<table align="center">

Example13
Loading editor…

Spring Boot Application with Spring JDBC Application

Example14
Loading editor…

Spring Boot Application with Spring JDBC Application

updateform.jsp:

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

Example15
Loading editor…

Spring Boot Application with Spring JDBC Application

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

Example16
Loading editor…

Spring Boot Application with Spring JDBC Application

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

Example17
Loading editor…

Spring Boot Application with Spring JDBC Application

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

13.<table align="center">

Example18
Loading editor…

Spring Boot Application with Spring JDBC Application

Example19
Loading editor…

Spring Boot Application with Spring JDBC Application

Editform.jsp

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

Example20
Loading editor…

Spring Boot Application with Spring JDBC Application

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

Example21
Loading editor…

Spring Boot Application with Spring JDBC Application

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

Example22
Loading editor…

Spring Boot Application with Spring JDBC Application

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

13.<table align="center">

Example23
Loading editor…

Spring Boot Application with Spring JDBC Application

Example24
Loading editor…

Spring Boot Application with Spring JDBC Application

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

Example25
Loading editor…

Spring Boot Application with Spring JDBC Application

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

Example26
Loading editor…

Spring Boot Application with Spring JDBC Application

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

Example27
Loading editor…

Spring Boot Application with Spring JDBC Application

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

14.<table align="center">

Example28
Loading editor…

Spring Boot Application with Spring JDBC Application

Example29
Loading editor…

Spring Boot Application with Spring JDBC Application

studentdetails.jsp:

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

Example30
Loading editor…

Spring Boot Application with Spring JDBC Application

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

Example31
Loading editor…

Spring Boot Application with Spring JDBC Application

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

Example32
Loading editor…

Spring Boot Application with Spring JDBC Application

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

Example33
Loading editor…

Spring Boot Application with Spring JDBC Application

success.jsp:

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

Example34
Loading editor…

Spring Boot Application with Spring JDBC Application

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

Example35
Loading editor…

Spring Boot Application with Spring JDBC Application

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

Example36
Loading editor…

Spring Boot Application with Spring JDBC Application

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

Example37
Loading editor…

Spring Boot Application with Spring JDBC Application

failure.jsp

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

Example38
Loading editor…

Spring Boot Application with Spring JDBC Application

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

Example39
Loading editor…

Spring Boot Application with Spring JDBC Application

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

Example40
Loading editor…

Spring Boot Application with Spring JDBC Application

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

Example41
Loading editor…

Spring Boot Application with Spring JDBC Application

existed.jsp

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

Example42
Loading editor…

Spring Boot Application with Spring JDBC Application

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

Example43
Loading editor…

Spring Boot Application with Spring JDBC Application

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

Example44
Loading editor…

Spring Boot Application with Spring JDBC Application

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

Example45
Loading editor…

Spring Boot Application with Spring JDBC Application

Notexisted.jsp

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

Example46
Loading editor…

Spring Boot Application with Spring JDBC Application

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

Example47
Loading editor…

Spring Boot Application with Spring JDBC Application

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

Example48
Loading editor…

Spring Boot Application with Spring JDBC Application

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

Example49
Loading editor…

Spring Boot Application with Spring JDBC Application

Example50
Loading editor…

StudentController.java

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

StudentController.java

Example52
Loading editor…

StudentController.java

10.import com.durgasoft.dto.Student;

11.import com.durgasoft.service.StudentService;

Example53
Loading editor…

StudentController.java

14.public class StudentController {

Example54
Loading editor…

StudentController.java

Example55
Loading editor…

StudentController.java

Example56
Loading editor…

StudentController.java

name,@RequestParam String saddr) {

Example57
Loading editor…

StudentController.java

Example58
Loading editor…

StudentController.java

Example59
Loading editor…

StudentController.java

Example60
Loading editor…

StudentController.java

Example61
Loading editor…

StudentController.java

Example62
Loading editor…

StudentController.java

sname, @RequestParam String saddr) {

Example63
Loading editor…

StudentController.java

Example64
Loading editor…

StudentController.java

Example65
Loading editor…

StudentController.java

100.

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

return status;

}

}

Example66
Loading editor…

StudentService.java

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

StudentService.java

Example68
Loading editor…

StudentService.java

Example69
Loading editor…

StudentService.java

Example70
Loading editor…

StudentServiceImpl.java

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

StudentServiceImpl.java

Example72
Loading editor…

StudentServiceImpl.java

Example73
Loading editor…

StudentServiceImpl.java

Example74
Loading editor…

StudentServiceImpl.java

10.public class StudentServiceImpl implements StudentService {

Example75
Loading editor…

StudentServiceImpl.java

Example76
Loading editor…

StudentServiceImpl.java

Example77
Loading editor…

StudentServiceImpl.java

Example78
Loading editor…

StudentServiceImpl.java

Example79
Loading editor…

StudentServiceImpl.java

Example80
Loading editor…

StudentServiceImpl.java

Example81
Loading editor…

StudentServiceImpl.java

Example82
Loading editor…

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
Loading editor…

StudentDaoImpl.java

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

package com.durgasoft.dao;

StudentDaoImpl.java

Example85
Loading editor…

StudentDaoImpl.java

Example86
Loading editor…

StudentDaoImpl.java

Example87
Loading editor…

StudentDaoImpl.java

10.public class StudentDaoImpl implements StudentDao {

Example88
Loading editor…

StudentDaoImpl.java

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

Example89
Loading editor…

StudentDaoImpl.java

Example90
Loading editor…

StudentDaoImpl.java

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

Example91
Loading editor…

StudentDaoImpl.java

Example92
Loading editor…

StudentDaoImpl.java

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

Example93
Loading editor…

StudentDaoImpl.java

Example94
Loading editor…

StudentDaoImpl.java

id+"'");

Example95
Loading editor…

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
Loading editor…

StudentDaoImpl.java

sd/maven-4.0.0.xsd">

Example97
Loading editor…

StudentDaoImpl.java

Example98
Loading editor…

StudentDaoImpl.java

Example99
Loading editor…

StudentDaoImpl.java

Example100
Loading editor…

StudentDaoImpl.java

Example101
Loading editor…

StudentDaoImpl.java

Example102
Loading editor…

StudentDaoImpl.java

Example103
Loading editor…
📝 Key Takeaways
  • Key ideas of Spring Boot - Spring JDBC Application explained simply
  • Ready-to-use code examples
  • Exam-style questions at the end

Finished this lesson?

Mark it as complete to track your progress and see technology completion stats.