Spring – Perform Update Operation in CRUD

Last Updated : 06 Sep, 2022
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

CRUD (Create, Read, Update, Delete) operations are the building block for developers stepping into the software industry. CRUD is mostly simple and straight forward except that real-time scenarios tend to get complex. Among CRUD operations, the update operation requires more effort to get right compared to the other three operations. A pre-loaded database table is a pre-requisite for carrying out CRUD operations Read involves only reading data from the database and displaying it in the user interface (UI). Create is also similarly simple as it only involves taking input from the user and entering the validated input into the database.

Update and delete tend to get more complex to understand as it will involve the usage of data structures and other webpage concepts such as params, JSP page, etc. This tutorial aims to simplify the update operation for first-timers in CRUD. Before we get to the tutorial, it would be beneficial to see the visual representation of the operations in the web pages and databases involved in the operations.

The image given below shows the database that is to be populated on the webpage:

 

This is how the populated table will look along with the update and delete action Buttons:

 

Once the update button is clicked, this is how the data gets populated into the form:

 

Example Project

To understand how Update works, it’s necessary to start with the read operation.  

Java




public List<Student> getStudents() throws Exception {
    List<Student> students = new ArrayList<>();
    // the ArrayList students contains
      // all the data from the database
    return students;
}


Now the ArrayList students now get returned to the webpage via a servlet.

Note: The actual read operation has a longer code. The code depicted here is just to throw some light on the data structures used in the create operation. The List<Student> declaration uses a class named Student with all the variables, getters, and setters to initialize the ArrayList object.

Before proceeding to the servlet, it would help a little to take a look at the object structure that would be used in this code while using ArrayLists.

Student.java

Java




package com.jdbc;
 
public class Student {
    private String name;
    private String gender;
    private String course;
    private int id;
     
    public Student(int id, String name,String course, String gender) {
        this.name = name;
        this.gender = gender;
        this.course = course;
        this.id = id;
    }
     
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getGender() {
        return gender;
    }
    public void setGender(String gender) {
        this.gender = gender;
    }
    public String getCourse() {
        return course;
    }
    public void setCourse(String course) {
        this.course = course;
    }
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    @Override
    public String toString() {
        return "Student [id=" + id + ", name" + name + ", course=" + course + ", gender=" + gender + "]";
    }
}


StudentControllerServlet.java

Java




import javax.annotation.Resource;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;
 
import com.jdbc.StudentDbUtil;
import com.jdbc.Student;
 
@WebServlet("/StudentControllerServlet")
public class StudentControllerServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
    private StudentDbUtil studentDbUtil;
 
private void listStudents(HttpServletRequest request, HttpServletResponse response)
        throws Exception {
 
        // get students from db util
        // This is where the database arraylist
          // is received in the servlet
        List<Student> students = studentDbUtil.getStudents();
         
        // add students to the request
        request.setAttribute("STUDENT_LIST", students);
                 
        // send to JSP page (view)
        RequestDispatcher dispatcher =     request.getRequestDispatcher("/CRUDform.jsp");
         
        dispatcher.forward(request, response);
    }
}


Code Explanation: 

  1. The ArrayList ‘students’ is named as STUDENT_LIST using the request.setAttribute method.
  2. A dispatcher to the webpage (CRUDform.jsp) is initialized using ‘RequestDispatcher dispatcher = request.getRequestDispatcher(“/CRUDform.jsp”);’ and the control if forwarded to the same webpage using ‘dispatcher.forward(request, response);’.

CRUDform.jsp

HTML




<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
   pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page import="java.util.*" %>
<!DOCTYPE html>
<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
      <title>Form</title>
   </head>
   <%
      // get students from the request object (sent by servlet)
      String crud = (String) request.getAttribute("COMMAND");
      if(crud == null){
        crud = "register";
        StudentControllerServlet s = new StudentControllerServlet();   
      }
      List<Student> theStudent = (List<Student>) request.getAttribute("STUDENT_LIST");    
       
      Student theStudents = (Student) request.getAttribute("THE_STUDENT");
      %>
   <body>
      <table id="example" class="table table-striped" style="width:100%">
         <thead>
            <tr>
               <th>Name</th>
               <th>Course</th>
               <th>Gender</th>
            </tr>
         </thead>
         <tbody>
            <c:forEach var="tempStudent" items="${STUDENT_LIST}">
            <!-- set up a link for each row -->
            <c:url var="tempLink" value="StudentControllerServlet">
               <c:param name="command" value="LOAD" />
               <c:param name="studentId" value="${tempStudent.id}" />
               <c:param name="crud" value="UPDATE" />
            </c:url>
            <!--  set up a link to delete a row -->
            <c:url var="deleteLink" value="StudentControllerServlet">
               <c:param name="command" value="DELETE" />
               <c:param name="studentId" value="${tempStudent.id}" />
            </c:url>
            <tr>
               <td> ${tempStudent.name} </td>
               <td> ${tempStudent.course} </td>
               <td> ${tempStudent.gender} </td>
               <td>
                  <a href="${tempLink}">Update</a>
                  |
                  <a href="${deleteLink}"
                     onclick="if (!(confirm('Are you sure you want to delete the entry with ID ${tempStudent.studentid} and studying in ${tempStudent.standard} year?'))) return false">Delete</a>   
               </td>
            </tr>
         </tbody>
      </table>
   </body>
</html>


The above example would require the usage of JSTL tags, database so make sure to install and add the required libraries (postgresql-42.3.1.jar, javax.servlet.jsp.jstl-1.2.1.jar, and javax.servlet.jsp.jstl-api-1.2.1.jar) in the project.

Code Explanation:  

  1. The ArrayList with the name “STUDENT_LIST” can be retrieved using Java code written between opening braces ‘<%’ and closing braces’%>’. The command ‘(List<Student>) request.getAttribute(“STUDENT_LIST”);’ gets the attribute ‘STUDENT_LIST’ from the servlet, typecasts it into an object defined in the class name Student, and then it is stored in the variable of Object type using the command ‘List<Student> theStudent = (List<Student>) request.getAttribute(“STUDENT_LIST”);’.
  2. Now the ArrayList named “theStudent” is what is used to populate tables with the database entries.
  3. Here comes the usage of JSTL tags. The <c:forEach> tag, which can be considered as a JSTL equivalent of the Java “for loop”, is used to iterate through the ArrayList “STUDENT_LIST” and the tag has to be defined as follows: <c:forEach var=”tempStudent” items=”${STUDENT_LIST}”> </c:forEach>.
  4. Between the opening and closing of <c:forEach> tag comes the code for populating the table.
  5. The <c:url> tag is used to format a URL into a string and store it into a variable and to perform URL rewriting when necessary. The <c:param> tag has the attributes name, value which sets the name and value of the request parameters in the URL respectively. Here, the name attribute is mandatory with no default value whereas the value parameter is not compulsory. For example, the tag ‘<c:url var=”tempLink” value=”StudentControllerServlet”><c:param name=”command” value=”LOAD” /><c:param name=”studentId” value=”${tempStudent.id}” /><c:param name=”crud” value=”UPDATE” /></c:url>’ writes the target URL as http://localhost:8001/HibernateStudent/StudentControllerServlet?command=LOAD&studentId=k16&id=3&crud=UPDATE where the attribute command is passed with value “LOAD” which is a vital attribute.
  6. When the button labeled as “UPDATE” corresponding to the LOAD attribute is pressed and the controller goes to the StudentControllerServlet mentioned in the URL given above.

StudentControllerServlet.java

Refer to this article Resource Injection in Java EE to understand the first line in the code snippet given below.

Java




@Resource(name="jdbc/test")
private DataSource dataSource;
 
@Override
public void init() throws ServletException {
    super.init();
       
// create our student db util ...
// and pass in the conn pool / datasource
try
{
    studentDbUtil = new StudentDbUtil(dataSource);
}
catch (Exception exc) {
    throw new ServletException(exc);
}
 
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    try {
    String theCommand = request.getParameter("command");
         
    switch (theCommand) {
      case "LOAD":
          loadStudent(request, response);
        break;
        }
    }
    catch (Exception exc) {
        throw new ServletException(exc);
    }
}
 
private void loadStudent(HttpServletRequest request, HttpServletResponse response)
            throws Exception {
             
    // read student id from form data
    int id = Integer.parseInt(request.getParameter("id"));
    String theStudentId = request.getParameter("studentId");
    String crud = request.getParameter("crud");
     
    // get student from database (db util)
    Student theStudent = studentDbUtil.getStudent(id);  
             
    // get students from db util and control continues           
    List<Student> students = studentDbUtil.getStudents();
             
    // add students to the request
    request.setAttribute("STUDENT_LIST", students);
             
    // place student in the request attribute
    request.setAttribute("THE_STUDENT", theStudent);
             
    request.setAttribute("COMMAND", "update");   
 
    // send to jsp page: CRUDform.jsp
    RequestDispatcher dispatcher = request.getRequestDispatcher("/CRUDform.jsp");
             
    dispatcher.forward(request, response);       
}


Code Explanation:  

  1. The annotation @Resource(name=”jdbc/test”) along with the command “private DataSource dataSource;” will be used to establish the database connection.
  2. The “LOAD” command declared on the previous page is received in the servlet using the “String theCommand = request.getParameter(“command”);” command and is accordingly the control goes into the update function as per the switch case statement.
  3. After entering into the loadstudent method, the attributes id, theStudentId, crud are received using requests from the previous page. Now the details corresponding to the particular ID are retrieved by invoking the “Student theStudent = studentDbUtil.getStudent(id);” by passing the ID as a parameter which is demonstrated in the code given below.

StudentDbUtil.java

Java




// point of resource injection
public DataSource dataSource;
      
public StudentDbUtil(DataSource theDataSource) {
    dataSource = theDataSource;
}
 
public Student getStudent(int theStudentId) throws Exception{
        Student theStudent = null;
         
        Connection myConn = null;
        PreparedStatement myStmt = null;
        ResultSet myRs = null;
        String studentId;
        try {
            // get connection to database
            myConn = dataSource.getConnection();
             
            //create sql to get selected student
        String sql = "select * from students where id=?";
 
        // create prepared statement
        myStmt = myConn.prepareStatement(sql);
             
        // set params
        myStmt.setInt(1, theStudentId);
             
        // execute statement
        myRs = myStmt.executeQuery();
             
        // retrieve data from result set row
        if (myRs.next()) {
            int id = myRs.getInt("id");
            String name = myRs.getString("name");
            String course = myRs.getString("course");
            String gender = myRs.getString("gender");
                 
            // create new student object
            theStudent = new Student(id, name, course, gender);
        }
        else {
            throw new Exception("Could not find student id: " + theStudentId);
        }   
        return theStudent;
        }
        finally {
            close(myConn, myStmt, myRs);
        }
    }


Code Explanation:  

  1. The line ‘studentDbUtil.getStudent(id);’ invokes the corresponding method in the StudentDbUtil.java class.
  2. The command ‘myConn = dataSource.getConnection();’ gets a connection to the database. After this command, the ‘myConn’ variable will be used to reference the database connectivity wherever required.
  3. After that, in the try block, the select query ‘String sql = “select * from students where id=?”;’, the prepared statement ‘myStmt = myConn.prepareStatement(sql);’ are declared and parameters are set for retrieving the corresponding data.
  4. The id is set in the query using ‘myStmt.setInt(1, theStudentId);’ and the select query is executed with ‘myRs = myStmt.executeQuery();’ and stored in the result set (myRs) variable.
  5. The result set is iterated and an object is invoked to store the data which is to be passed to the webpage.
  6. The connection is closed in the finally block and now it’s time to return the control to the servlet.

Java




private void loadStudent(HttpServletRequest request, HttpServletResponse response)
            throws Exception {                                                             
             
    // get students from db util and control continues           
    List<Student> students = studentDbUtil.getStudents();
             
    // add students to the request
    request.setAttribute("STUDENT_LIST", students);
             
    // place student in the request attribute. This is what is used to pre-populate the form with data from the database.
    request.setAttribute("THE_STUDENT", theStudent);
     
    // the attribute command is set to update for identification purpose.       
    request.setAttribute("COMMAND", "update");   
 
    // send to jsp page: CRUDform.jsp
    RequestDispatcher dispatcher = request.getRequestDispatcher("/CRUDform.jsp");
             
    dispatcher.forward(request, response);       
}


The control gets directed to CRUDform.jsp page and the attributes are checked within the ‘<%’ and ‘%>’ tags before the body tags to decide whether it is an update or list, or register operation.

HTML




<%
   // get students from the request object (sent by servlet)
   String crud = (String) request.getAttribute("COMMAND");
   if(crud == null){
       crud = "register";
       StudentControllerServlet s = new StudentControllerServlet();   
   }
    
   List<Student> theStudent = (List<Student>) request.getAttribute("STUDENT_LIST");    
    
   Student theStudents = (Student) request.getAttribute("THE_STUDENT");
   %>
<body>
   <div class="container">
   <div class="title">FORM</div>
   <div class="content">
   <form name="myForm" action="StudentControllerServlet" method="POST" onsubmit="return validateForm()">
      <%
         if(crud.equals("register")){%>
      <input type="hidden" name="command" value="ADD" />
      <%}else if(crud.equals("update")){%>
      <input type="hidden" name="command" value="UPDATE" />
      <input type="hidden" name="id" value="${THE_STUDENT.id}" />
      <%}
         %>
      <div class="user-details">
      <div class="input-box">
         <span class="details">Name </span>
         <input type="text" name="name" placeholder="Enter name" required value="${THE_STUDENT.name}"/> <br><br>
      </div>
      <div class="input-box">
         <span class="details">Course </span>
         <select name="course" id="course">
            <%if(crud.equals("register")){%>
            <option value="CSE">CSE</option>
            <option value="IT">IT</option>
            <option value="ECE">ECE</option>
            <br><br>
         </select>
         <%}else if(crud.equals("update")){%>
         <%if(theStudents.getCourse().equals("CSE")){%>
         <option value="CSE" selected>CSE</option>
         <%}else{%>
         <option value="CSE">CSE</option>
         <%}%>
         <%if(theStudents.getCourse().equals("IT")){%>
         <option value="IT" selected>IT</option>
         <%}else{%>
         <option value="IT">IT</option>
         <%}%>
         <%if(theStudents.getCourse().equals("ECE")){%>
         <option value="ECE" selected>ECE</option>
         <%}else{%>
         <option value="ECE">ECE</option>
         <%}%>
         <%}%>
         </select>
         <%if(crud.equals("register")){%>
         <input type="radio" id="male" name="gender" value="Male"
         <label for="male">Male </label>
         <label for="male">Female </label>
         <label for="male">Transgender </label>
         </select>
         <%}else if(crud.equals("update")){%>
         <%if(theStudents.getGender().equals("Male")){%>
         <input type="radio" id="male" name="gender" value="Male" checked> 
         <label for="male">Male </label>
         <%}else{%>
         <input type="radio" id="male" name="gender" value="Male"
         <label for="male">Male </label>
         <%}%>
         <%if(theStudents.getGender().equals("Female")){%>
         <input type="radio" id="female" name="gender" value="Female" checked> 
         <label for="female">Female </label>
         <%}else{%>
         <input type="radio" id="female" name="gender" value="Female"
         <label for="female">Female </label>
         <%}%>
         <%if(theStudents.getGender().equals("Transgender")){%>
         <input type="radio" id="transgender" name="gender" value="Transgender" checked> 
         <label for="transgender">Transgender </label>
         <%}else{%>
         <input type="radio" id="transgender" name="gender" value="Transgender"
         <label for="transgender">Transgender </label>
         <%}%>
         <%}%>
      </div>
      <%
         if(crud.equals("update")){%>
      <button name="submit" value="SUBMIT" type="submit">Update</button>
      <%}else if(crud.equals("register")){%>
      <button name="submit" value="SUBMIT" type="submit">Register</button>
      <%}%>       
   </form>


Code Explanation:

  1. The attribute “COMMAND” is received in the JSP page using ‘String crud = (String) request.getAttribute(“COMMAND”);’ and stored in the variable named ‘crud’.
  2. The ArrayLists ‘List<Student> theStudent = (List<Student>) request.getAttribute(“STUDENT_LIST”);’ and ‘Student theStudents = (Student) request.getAttribute(“THE_STUDENT”);’ are received from the servlet.
  3. The value of ‘crud’ is checked and if it has the value “update” then a hidden input type is initiated to indicate that the operation is an “update” operation when the form is submitted.
  4. Auto populating a text or date picker field is straightforward enough, adding value=”${THE_STUDENT.name}” to the corresponding tag will do the work. Here, THE_STUDENT denotes the ArrayList name, name denotes the ‘name variable’ in the ArrayList and ${} is used since it’s Java code being used in HTML.
  5. Now comes the real challenge for beginners, the value attribute does not work in dropdown or radio buttons. This is where JSTL tags come to save the day.
  6. Condition checking is done and components are auto selected accordingly. For example, the command <%if(theStudents.getCourse().equals(“CSE”)){%> checks if the value of course in the ArrayList is equal to CSE and if the condition is satisfied then the option CSE is auto selected in the dropdown using <option value=”CSE” selected>CSE</option>. If not, then the else clause is executed where the HTML tag is entered without being selected <%}else{%> <option value=”CSE”>CSE</option> <%}%>
  7. The above if and else in JSTL format can also be applied for radio buttons for auto-selecting according to the data in the database only change is the usage of “checked” keyword instead of selected as demonstrated in the code given above.
  8. The control goes to the servlet code given below when the form is submitted.

StudentControllerServlet.java

Java




protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        try {
            // read the "command" parameter
            String theCommand = request.getParameter("command");
             
            // route to the appropriate method
            switch (theCommand) {
                 
            case "UPDATE":
            updateStudent(request, response);
            break;
                 
            }
        catch (Exception exc) {
            throw new ServletException(exc);
        }
         
    }
 
private void updateStudent(HttpServletRequest request, HttpServletResponse response)
            throws Exception {
            // read student info from form data
            int id = Integer.parseInt(request.getParameter("id"));
            String name = request.getParameter("name");
            String course = request.getParameter("course");
            String gender = request.getParameter("gender");
            // create a new student object
            Student theStudent = new Student(id,name,course,gender);
             
            // perform update on database
            studentDbUtil.updateStudent(theStudent);
             
            // get students from db util
            List<Student> students = studentDbUtil.getStudents();
             
            // add students to the request
            request.setAttribute("STUDENT_LIST", students);
         
            // send them back to the "list students" page
            listStudents(request, response);
    }


As demonstrated in the previous servlet example, the control goes to the database class in the line ‘studentDbUtil.updateStudent(theStudent);’

StudentDbUtil.java

Java




public void updateStudent(Student theStudent) throws Exception{
        Connection myConn = null;
        PreparedStatement myStmt = null;
         
        try {
            // get connection to database
            myConn = dataSource.getConnection();
             
            // create SQL update statement
            String sql = "update student "
                    + "set  name=?,gender=?,course=? "
                    + "where id=?";
             
            // prepare statement
            myStmt = myConn.prepareStatement(sql);
             
            //set params
            myStmt.setString(1, theStudent.getName());
            myStmt.setString(2, theStudent.getGender());
            myStmt.setString(3, theStudent.getCourse());
            myStmt.setInt(4, theStudent.getId());   
     
            myStmt.execute();
        }
        finally {
            // clean up JDBC objects
            close(myConn, myStmt, null);
        }
    }


Now the connection is established, the query is written and the query is executed in the code given above. Update is the comparatively harder part of CRUD operations, especially populating radio buttons and dropdown lists and it has been simplified to a large extent in this article. So, we’re done now!

Note: It is highly recommended to create a SERIAL column named ‘id’ when creating the table and then use that unrelated column in the WHERE clause of SQL queries so as to avoid errors while executing queries.



Previous Article
Next Article

Similar Reads

How to Perform CRUD Operations in Room Database in Android?
Data from the app can be saved on users' devices in different ways. We can store data in the user's device in SQLite tables, shared preferences, and many more ways. In this article, we will take a look at saving data, reading, updating, and deleting data in Room Database on Android. We will perform CRUD operations using Room Database on Android. In
15+ min read
Simplifying CRUD Operation with JDBC
Creating, reading, updating, and deleting data in a database is a common task in many applications, and JDBC (Java Database Connectivity) is a Java API that allows you to connect to a database and perform these operations. In this blog post, we will walk through the steps of setting up a simple CRUD (create, read, update, delete) operation using JD
3 min read
CRUD Operation in MySQL Using PHP, Volley Android - Read Data
In the previous article, we have performed the insert data operation. In this article, we will perform the Read data operation. Before performing this operation first of all we have to create a new PHP script for reading data from SQL Database. Prerequisite: You should be having Postman installed in your system to test this PHP script. Create a PHP
9 min read
CRUD Operation in MySQL Using PHP, Volley Android - Insert Data
It is known that we can use MySQL to use Structure Query Language to store the data in the form of RDBMS. SQL is the most popular language for adding, accessing and managing content in a database. It is most noted for its quick processing, proven reliability, ease, and flexibility of use. The application is used for a wide range of purposes, includ
10 min read
User Authentication and CRUD Operation with Firebase Realtime Database in Android
Firebase is a famous product of Google which is used by so many developers to add backend functionality for their website as well as apps. The Firebase will make your job really easier for the backend database and handling the database. In this article, we will take a look at the implementation of the Firebase Realtime Database in Android. In this
15+ min read
Servlet - CRUD Operation with Example
CRUD means Create, Read, Update and Delete. These are the basic important operations carried out on the Database and in applications. We will build a simple User registration application using a Servlet, MYSQL, and JDBC for demonstration. In this example, we will be able to create users, read users, update users and delete users. Technology tools:
10 min read
Spring Boot - CRUD Operations using MySQL Database
CRUD stands for Create, Read/Retrieve, Update and Delete and these are the four basic operations that we perform on persistence storage. CRUD is data-oriented and the standardized use of HTTP methods. HTTP has a few methods which work as CRUD operations and do note they are very vital from a developmental point perspective in programming that also
7 min read
Spring Boot - CRUD Operations using MongoDB
CRUD stands for Create, Read/Retrieve, Update, and Delete and these are the four basic operations that we perform on persistence storage. CRUD is data-oriented and the standardized use of HTTP methods. HTTP has a few methods which work as CRUD operations and do note they are very vital from a developmental point perspective in programming that also
5 min read
Spring MVC CRUD with Example
CRUD stands for Create, Read/Retrieve, Update, and Delete. These are the four basic operations to create any type of project. Spring MVC is a Web MVC Framework for building web applications. It is a spring module same as Spring boot, spring-security, etc. The term MVC stands for Model-View-Controller architecture. In this article, we will be buildi
7 min read
Spring Boot - CRUD Operations
CRUD stands for Create, Read/Retrieve, Update, and Delete and these are the four basic operations that we perform on persistence storage. CRUD is data-oriented and the standardized use of HTTP methods or there is a term for this called HTTP action verbs. HTTP has a few action verbs or methods that work as CRUD operations and do note they are vital
7 min read
Spring Boot - CRUD Operations Using Redis Database
Redis is an in-memory data structure that is used for faster access to data. It is used to store data that needs to be accessed frequently and fast. It is not used for storing large amounts of data. If you want to store and retrieve large amounts of data you need to use a traditional database such as MongoDB or MYSQL. Redis provides a variety of da
8 min read
Spring MVC and Hibernate CRUD Example
In this article, we will be developing CRUD operations in Spring MVC and Hibernate. Hibernate is an object-relational mapping (ORM) framework. Developers use Hibernate to interact with databases using Java objects rather than SQL queries. Spring MVC is a Model-View-Controller (MVC) framework used to build web applications in Java. The Spring MVC pa
6 min read
Testing Spring WebFlux Reactive CRUD Rest APIs Using WebTestClient
Spring Boot is one of the famous frameworks for Back-end development. The Spring Boot Community Developed the Spring Reactive Web Framework. This Reactive Framework is available from Spring Boot 5.0 and Above versions only. The Spring Reactive allows developers to build Asynchronous, Non-Blocking, and Event-Driven Web Applications. When compared wi
8 min read
Spring Boot - Spring JDBC vs Spring Data JDBC
Spring JDBC Spring can perform JDBC operations by having connectivity with any one of jars of RDBMS like MySQL, Oracle, or SQL Server, etc., For example, if we are connecting with MySQL, then we need to connect "mysql-connector-java". Let us see how a pom.xml file of a maven project looks like. C/C++ Code &lt;?xml version=&quot;1.0&quot; encoding=
4 min read
Difference Between Spring DAO vs Spring ORM vs Spring JDBC
The Spring Framework is an application framework and inversion of control container for the Java platform. The framework's core features can be used by any Java application, but there are extensions for building web applications on top of the Java EE platform. Spring-DAO Spring-DAO is not a spring module. It does not provide interfaces or templates
5 min read
Spring vs Spring Boot vs Spring MVC
Are you ready to dive into the exciting world of Java development? Whether you're a seasoned pro or just starting out, this article is your gateway to mastering the top frameworks and technologies in Java development. We'll explore the Spring framework, known for its versatility and lightweight nature, making it perfect for enterprise-level softwar
8 min read
PostgreSQL CRUD Operations using Java
CRUD (Create, Read, Update, Delete) operations are the basic fundamentals and backbone of any SQL database system. CRUD is frequently used in database and database design cases. It simplifies security control by meeting a variety of access criteria. The CRUD acronym identifies all of the major functions that are inherent to relational databases and
8 min read
Servlet - CRUD
CRUD means Create, Read, Update and Delete. These are the basic important operations carried out on the Database and in applications. We can able to manipulate the tables of any database using CRUD operations. Here in this article, let us take MYSQL for it. Table creation in MySQL -- Let us keep the db name as geeksforgeeks -- Table name geekusers
10 min read
CRUD Operations in Student Management System in Java
CRUD stands for Create, Read/Retrieve, Update and Delete and these are the four basic operations that we perform on persistence storage. CRUD is data-oriented and the standardized use of HTTP methods. HTTP has a few methods which work as CRUD operations and do note they are very vital from a developmental point perspective in programming that also
7 min read
CRUD Operations using Hibernate
Hibernate is a Java framework that implements ORM(Object Relational Mapping) design pattern. It is used to map java objects into a relational database. It internally uses JDBC(Java Database Connectivity), JTA(Java Transaction API), and JNDI(Java Naming and Directory Interface). It helps to make java objects persist in the database without losing th
5 min read
Java Spring Boot Microservices - Develop API Gateway Using Spring Cloud Gateway
The API Gateway Pattern in some cases stands for “Backend for frontend”. It is basically the entry gate for taking entry into any application by an external source. The pattern is going on in a programmer’s mind while they are making the client’s application. It acts as a medium between the client applications and microservices. For example-Netflix
4 min read
Spring Boot | How to access database using Spring Data JPA
Spring Data JPA is a method to implement JPA repositories to add the data access layer in applications easily. CRUD stands for create, retrieve, update, delete which are the possible operations which can be performed in a database. In this article, we will see an example of how to access data from a database(MySQL for this article) in a spring boot
4 min read
How to Create a Spring Boot Project in Spring Initializr and Run it in IntelliJ IDEA?
Java language is one of the most popular languages among all programming languages. There are several advantages of using the java programming language, whether for security purposes or building large distribution projects. One of the advantages of using Java is that it tries to connect every concept in the language to the real world with the help
3 min read
Spring - Add User Name and Password in Spring Security
Spring Security is a powerful and highly customizable authentication and access-control framework. It is the de-facto standard for securing Spring-based applications. Spring Security is a framework that focuses on providing both authentication and authorization to Java applications. Like all Spring projects, the real power of Spring Security is fou
3 min read
How to Create and Setup Spring Boot Project in Spring Tool Suite?
Spring Boot is built on the top of the spring and contains all the features of spring. And is becoming a favorite of developers these days because of its rapid production-ready environment which enables the developers to directly focus on the logic instead of struggling with the configuration and setup. Spring Boot is a microservice-based framework
3 min read
How to Run Your First Spring Boot Application in Spring Tool Suite?
Spring Tool Suite (STS) is a java IDE tailored for developing Spring-based enterprise applications. It is easier, faster, and more convenient. And most importantly it is based on Eclipse IDE. STS is free, open-source, and powered by VMware. Spring Tools 4 is the next generation of Spring tooling for the favorite coding environment. Largely rebuilt
3 min read
Spring - Add Roles in Spring Security
Spring Security is a powerful and highly customizable authentication and access-control framework. It is the de-facto standard for securing Spring-based applications. Spring Security is a framework that focuses on providing both authentication and authorization to Java applications. Like all Spring projects, the real power of Spring Security is fou
4 min read
Difference Between Spring Boot Starter Web and Spring Boot Starter Tomcat
Spring Boot is built on the top of the spring and contains all the features of spring. And is becoming a favorite of developers these days because of its rapid production-ready environment which enables the developers to directly focus on the logic instead of struggling with the configuration and setup. Spring Boot is a microservice-based framework
3 min read
Create and Run Your First Spring MVC Controller in Eclipse/Spring Tool Suite
Spring MVC framework enables separation of modules namely Model, View, and Controller, and seamlessly handles the application integration. This enables the developer to create complex applications also using plain java classes. The model object can be passed between view and controller using maps. In this article, we will see how to set up a Spring
5 min read
Spring - Using SQL Scripts with Spring JDBC + JPA + HSQLDB
We will be running the SQL scripts with Spring JDBC +JPA + HSQLDB. These scripts are used to perform SQL commands at the time of application start. Java Database Connectivity (JDBC) is an application programming interface (API) for the programming language Java, which defines how a client may access a database. JPA is just a specification that faci
3 min read
Article Tags :
Practice Tags :