Aditya JAVA PROJECT
Aditya JAVA PROJECT
0 Rationale
Servlets in Java are essential for developing dynamic and interactive web
applications. They enable server-side processing, allowing for the generation of
dynamic content, handling user requests, and interacting with databases. Servlets offer
a robust and scalable approach to web development, as they can manage complex
business logic and maintain state between multiple client interactions. They also
provide a foundation for building RESTFUL APIs and integrating with various
frameworks and libraries. By performing a servlet program in Java, developers can
create efficient and feature-rich web applications that offer a seamless user experience
and meet the demands of modern web development.
Benefits:
a) Able to perform operations such as create, update, read and delete
b) Able to execute curd operations in servlet.
Gathered all the possible information about CURD operation from various sources
like:
a) Books on Advance Java.
2. Literature Review:
All the information collected from various sources, such as books, articles,
reports, manuals, websites, and more, regarding the CURD operations and
implementation of these operations has been thoroughly reviewed and discussed
within our project group.
JDBC
JDBC stands for Java Database Connectivity. It is a Java-based API (Application
Programming Interface) that allows Java applications to interact with relational
databases. JDBC provides a standardized way for Java programs to connect to and
manipulate data stored in databases, such as MySQL, Oracle, PostgreSQL, Microsoft
SQL Server, and many others.
Sr. Name of
Specification
No. Resources/Material
3. Software 1.MS-Word
5.0 Code
1. Database Connection Class
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.io.IOException;
import java.sql.*;
@WebServlet("/books")
// CREATE operation
stmt.setString(1, title);
stmt.setString(2, author);
stmt.setDouble(3, price);
stmt.setInt(4, quantity);
stmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
// READ operation
while (rs.next()) {
} catch (SQLException e) {
e.printStackTrace();
}
protected void doPut(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// UPDATE operation
int id = Integer.parseInt(request.getParameter("id"));
stmt.setString(1, title);
stmt.setString(2, author);
stmt.setDouble(3, price);
stmt.setInt(4, quantity);
stmt.setInt(5, id);
stmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
protected void doDelete(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// DELETE operation
int id = Integer.parseInt(request.getParameter("id"));
stmt.setInt(1, id);
stmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
6.0 Output