Ipw 1&2
Ipw 1&2
A)Importance of Class.forName(): The Class.forName() method is used to dynamically load the JDBC driver
class into memory. In JDBC, each database vendor provides its own implementation of the JDBC driver, which
is responsible for facilitating communication between the Java application and the specific database
management system (DBMS). By using Class.forName(), the driver class is loaded and registered with the
DriverManager, allowing it to be used to establish connections to the corresponding database.
try {
// Dynamically load the JDBC driver class
Class.forName("com.mysql.cj.jdbc.Driver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
Importance of DriverManager.getConnection():
The DriverManager.getConnection() method is used to establish a connection to the database using the
registered JDBC driver. It takes a database URL, username, and password as parameters and returns a
Connection object representing the connection to the database. This connection object is then used to create
statements, execute queries, and perform other database operations.
try {
// Establish connection to the database
Connection connection = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/mydatabase", "username", "password");
// Perform database operations using the connection
// Close the connection when done
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
A)
4) Develop a JSP script that illustrates the usage of JSP expressions and JSP directives?
GenericServlet HttpServlet
GenericServiet is not dependent on any particular HttpServlet is a dependent protocol and is only used
protocol. It can be used with any protocol such as with HTTP protocol.
HTTP, SMTP, FTP, and so on.
All methods are concrete except the service() All methods are concrete (non-abstract). service() is
method. service() method is an abstract method. non-abstract method. service() can be replaced by
doGet() or doPost() methods.
It forwards and includes a request and is also It forwards and includes a request but it is not
possible to redirect a request. possible to redirect the request.
GenericServlet doesn’t allow session management HTTPServlet allows session management with
with cookies and HTTP sessions. cookies and HTTP sessions.
8) Demonstrate a JSP script that illustrates the usage of sendRedirect() method to redirect the user to
another page?
A)<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Redirect Example</title>
</head>
<body>
<h2>Redirect Example</h2>
<%
// Check some condition (for demonstration)
boolean redirect = true;
if (redirect) {
// Redirect to another page
response.sendRedirect("destination.jsp");
} else {
// Output some content if not redirected
%>
<p>You will not be redirected.</p>
<%
}
%>
</body>
</html>
Destination.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Destination Page</title>
</head>
<body>
<h2>Welcome to the Destination Page</h2>
<p>This is the page where you have been redirected.</p>
</body>
</html>
9) Assume Customer table in Oracle Database with following fields (CustID, CustName, Address, Mobile).
a) Create a HTML form to enter the data in to above fields along with submit button. b) Write JSP code to
insert data submitted by the user through the above HTML form into Customer Table?
A)<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Customer Registration Form</title>
</head>
<body>
<h2>Customer Registration Form</h2>
<form action="insertCustomer.jsp" method="post">
<label for="custName">Name:</label>
<input type="text" id="custName" name="custName" required><br><br>
<label for="address">Address:</label>
<input type="text" id="address" name="address" required><br><br>
<label for="mobile">Mobile:</label>
<input type="text" id="mobile" name="mobile" required><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
insertCustomer.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert Customer Data</title>
</head>
<body>
<h2>Insert Customer Data</h2>
<%
// Retrieve form data submitted by the user
String custName = request.getParameter("custName");
String address = request.getParameter("address");
String mobile = request.getParameter("mobile");
// JDBC Connection variables
String url = "jdbc:oracle:thin:@localhost:1521:XE"; // Oracle database URL
String username = "your_username";
String password = "your_password";
// SQL query to insert data into Customer table
String sql = "INSERT INTO Customer (CustName, Address, Mobile) VALUES (?, ?, ?)";
// Establish database connection
try {
Class.forName("oracle.jdbc.driver.OracleDriver"); // Load Oracle JDBC driver
Connection conn = DriverManager.getConnection(url, username, password)
// Create PreparedStatement to execute SQL query
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setString(1, custName);
pstmt.setString(2, address);
pstmt.setString(3, mobile);
// Execute the query
int rowsInserted = pstmt.executeUpdate();
if (rowsInserted > 0) {
out.println("<p>Customer data inserted successfully.</p>");
} else {
out.println("<p>Failed to insert customer data.</p>");
}
// Close PreparedStatement and Connection
pstmt.close();
conn.close();
} catch (Exception e) {
out.println("<p>Error: " + e.getMessage() + "</p>"); }
11) Develop a Servlet script that receives and display the following data entered by the user through
HTML form - FirstName, LastName and Address?
A)import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
@WebServlet("/UserDetailsServlet")
public class UserDetailsServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
// Retrieve user input data
String firstName = request.getParameter("firstName");
String lastName = request.getParameter("lastName");
String address = request.getParameter("address");
// Display user details
out.println("<!DOCTYPE html>");
out.println("<html>");
out.println("<head>");
out.println("<meta charset=\"UTF-8\">");
out.println("<title>User Details</title>");
out.println("</head>");
out.println("<body>");
out.println("<h2>User Details</h2>");
out.println("<p><strong>First Name:</strong> " + firstName + "</p>");
out.println("<p><strong>Last Name:</strong> " + lastName + "</p>");
out.println("<p><strong>Address:</strong> " + address + "</p>");
out.println("</body>");
out.println("</html>"); } }
12) Assume Books table in oracle database with following fields ( ISBN, Title, Author, Price) a) Create a
HTML that prompts the user to enter a Book Title and Updated Price along with a Submit Button. b) Write
Servlet code to Update the price of the book entered by the user.
A)<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Update Book Price</title>
</head>
<body>
<h2>Update Book Price</h2>
<form action="UpdateBookPriceServlet" method="post">
<label for="title">Book Title:</label>
<input type="text" id="title" name="title" required><br><br>
<label for="price">Updated Price:</label>
<input type="number" id="price" name="price" min="0" step="0.01" required><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
UpdateBookPriceServlet.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.sql.*;
@WebServlet("/UpdateBookPriceServlet")
public class UpdateBookPriceServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
// Retrieve book title and updated price entered by the user
String title = request.getParameter("title");
double price = Double.parseDouble(request.getParameter("price"));
// JDBC Connection variables
String url = "jdbc:oracle:thin:@localhost:1521:XE"; // Oracle database URL
String username = "your_username";
String password = "your_password";
// SQL query to update book price
String sql = "UPDATE Books SET Price = ? WHERE Title = ?";
// Establish database connection
try {
Class.forName("oracle.jdbc.driver.OracleDriver"); // Load Oracle JDBC driver
Connection conn = DriverManager.getConnection(url, username, password);
// Create PreparedStatement to execute SQL query
PreparedStatement pstmt = conn.prepareStatement(sql); pstmt.setDouble(1, price);
pstmt.setString(2, title);
if (rowsUpdated > 0) {
} else {
}
// Close PreparedStatement and Connection
pstmt.close();
conn.close();
} catch (Exception e) {
out.println("<p>Error: " + e.getMessage() + "</p>");
}
}
}
13) Assume Customers table in oracle database with following fields ( CustID, CName, City, Mobile) a)
Create a HTML form that prompts the user to select city from a drop down list along with submit button.
b) Write JSP code to display the records of all customers who belongs to that city as selected by the user
through the HTML form?
A)<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Select City</title>
</head>
<body>
<h2>Select City</h2>
<form action="DisplayCustomers.jsp" method="post">
<label for="city">Select City:</label>
<select id="city" name="city">
<option value="New York">New York</option>
<option value="Los Angeles">Los Angeles</option>
<option value="Chicago">Chicago</option>
<!-- Add more city options as needed -->
</select><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
DisplayCustomers.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Customers in City</title>
</head>
<body>
<h2>Customers in City</h2>
<%
// Retrieve selected city from the form
String city = request.getParameter("city");
// JDBC Connection variables
String url = "jdbc:oracle:thin:@localhost:1521:XE"; // Oracle database URL
String username = "your_username";
String password = "your_password";
// SQL query to select customers in the selected city
String sql = "SELECT * FROM Customers WHERE City = ?";
// Establish database connection
try {
Class.forName("oracle.jdbc.driver.OracleDriver"); // Load Oracle JDBC driver
Connection conn = DriverManager.getConnection(url, username, password);
// Create PreparedStatement to execute SQL query
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setString(1, city);
// Execute the query
ResultSet rs = pstmt.executeQuery();
// Display customer records
out.println("<table border='1'>");
out.println("<tr><th>CustID</th><th>CName</th><th>City</th><th>Mobile</th></tr>");
while (rs.next()) {
out.println("<tr>");
out.println("<td>" + rs.getInt("CustID") + "</td>");
out.println("<td>" + rs.getString("CName") + "</td>");
out.println("<td>" + rs.getString("City") + "</td>");
out.println("<td>" + rs.getString("Mobile") + "</td>");
out.println("</tr>");
}
out.println("</table>");
// Close ResultSet, PreparedStatement, and Connection
rs.close();
pstmt.close();
conn.close();
} catch (Exception e) {
out.println("<p>Error: " + e.getMessage() + "</p>");
}
%>
</body>
</html>
14) Build JSP code to validate the mobile number entered by the user. A VALID mobile number has exactly
10 digits. If the mobile number is valid display the message “ Thanks for providing your contact number”
else display the message “ Invalid Mobile Number”?
A)<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Mobile Number Validation</title>
</head>
<body>
<h2>Mobile Number Validation</h2>
<form action="MobileNumberValidation.jsp" method="post">
<label for="mobile">Enter Mobile Number:</label>
<input type="text" id="mobile" name="mobile" required><br><br>
<input type="submit" value="Validate">
</form>
<%
String mobileNumber = request.getParameter("mobile");
String message = "";
// Check if mobile number is exactly 10 digits
if (mobileNumber != null && mobileNumber.length() == 10 && mobileNumber.matches("\\d+")) {
message = "Thanks for providing your contact number";
} else {
message = "Invalid Mobile Number";
}
// Display validation message
out.println("<p>" + message + "</p>");
%>
</body>
</html>
15) Assume Users table in oracle database with following fields ( Username, Password) a) Create a HTML
form with Username and password Fields along with submit button. b) Develop JSP code that validates
the username and password fields and displays a welcome message for a valid user. (Assume a record
with username as ‘admin’ and password as “admin123’)
A)<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Login Form</title>
</head>
<body>
<h2>Login Form</h2>
<form action="LoginValidation.jsp" method="post">
<label for="username">Username:</label>
<input type="text" id="username" name="username" required><br><br>
<label for="password">Password:</label>
<input type="password" id="password" name="password" required><br><br>
<input type="submit" value="Login">
</form>
</body>
</html>
LoginValidation.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Login Validation</title>
</head>
<body>
<h2>Login Validation</h2>
<%
String username = request.getParameter("username");
String password = request.getParameter("password");
// Hardcoded valid credentials
String validUsername = "admin";
String validPassword = "admin123";
// Validate username and password
if (username != null && password != null && username.equals(validUsername) &&
password.equals(validPassword)) {
// Display welcome message for valid user
%>
<p>Welcome, <%= username %>!</p>
<%
} else {
// Display error message for invalid user
%>
<p>Invalid username or password. Please try again.</p>
<%
}
%>
</body>
</html>
16) Explain the architecture of JDBC?
A)Architecture of JDBC
Description:
->Application: It is a java applet or a servlet that communicates with a data source.
->The JDBC API: The JDBC API allows Java programs to execute SQL statements and retrieve results. Some of
the important classes and interfaces defined in JDBC API are as follows:
->DriverManager: It plays an important role in the JDBC architecture. It uses some database-specific drivers to
effectively connect enterprise applications to databases.
->JDBC drivers: To communicate with a data source through JDBC, you need a JDBC driver that intelligently
communicates with the respective data source.
Types of JDBC Architecture(2-tier and 3-tier)
The JDBC architecture consists of two-tier and three-tier processing models to access a database. They are as
described below:
Two-tier model: A java application communicates directly to the data source. The JDBC driver enables the
communication between the application and the data source. When a user sends a query to the data source,
the answers for those queries are sent back to the user in the form of results.
The data source can be located on a different machine on a network to which a user is connected. This is
known as a client/server configuration, where the user’s machine acts as a client, and the machine has the
data source running acts as the server.
Three-tier model: In this, the user’s queries are sent to middle-tier services, from which the commands are
again sent to the data source. The results are sent back to the middle tier, and from there to the user.
This type of model is found very useful by management information system directors.
18) Develop a java program to select records from a table using JDBC application?
A) import java.sql.*;
public class SelectRecordsExample {
public static void main(String[] args) {
// JDBC Connection variables
String url = "jdbc:mysql://localhost:3306/mydatabase"; // Database URL
String username = "your_username";
String password = "your_password";
// SQL query to select records from EMP table
String sql = "SELECT * FROM EMP";
// Establish database connection
try {
// Load the MySQL JDBC driver
Class.forName("com.mysql.cj.jdbc.Driver");
19) K L University maintains a library of Books written by their faculty members which are published by
different Publishers. Create a JDBC application that helps the librarian to perform some basic operations
like a) Adding a book to the database b) Fetching the details of the book including the Author information?
A) import java.sql.*;
public class LibraryManagementSystem {
// JDBC URL, username, and password
static final String JDBC_URL = "jdbc:mysql://localhost:3306/library";
static final String USERNAME = "your_username";
static final String PASSWORD = "your_password";
public static void main(String[] args) {
try {
// Establishing a connection to the database
Connection connection = DriverManager.getConnection(JDBC_URL, USERNAME, PASSWORD);
System.out.println("Connected to the database");
// Adding a book to the database
addBook(connection, "Introduction to Java", "John Smith", "ABC Publications");
// Fetching details of a book
fetchBookDetails(connection, "Introduction to Java");
// Closing the connection
connection.close();
System.out.println("Disconnected from the database");
} catch (SQLException e) {
e.printStackTrace();
}
}
// Method to add a book to the database
static void addBook(Connection connection, String title, String author, String publisher) throws SQLException
{
String sql = "INSERT INTO books (title, author, publisher) VALUES (?, ?, ?)";
PreparedStatement statement = connection.prepareStatement(sql);
statement.setString(1, title);
statement.setString(2, author);
statement.setString(3, publisher);
int rowsAffected = statement.executeUpdate();
if (rowsAffected > 0) {
20) An Admin of a Car selling company to add and view Car information details as per the design
specifications. The data received from the user (Admin) will be stored in database and retrieved when
required. Create required database and tables, to insert records into tables using JDBC application
Program?
A) CREATE DATABASE car_selling_company;
USE car_selling_company;
CREATE TABLE Cars (
CarID INT AUTO_INCREMENT PRIMARY KEY,
Brand VARCHAR(255) NOT NULL,
Model VARCHAR(255) NOT NULL,
Year INT NOT NULL,
Price DECIMAL(10, 2) NOT NULL
);
import java.sql.*;
public class CarSellingCompany {
public static void main(String[] args) {
// JDBC Connection variables
String url = "jdbc:mysql://localhost:3306/car_selling_company"; // Database URL
String username = "your_username";
String password = "your_password";
try {
// Load the MySQL JDBC driver
Class.forName("com.mysql.cj.jdbc.Driver");
// Create a connection to the database
Connection connection = DriverManager.getConnection(url, username, password);
// Inserting records into the Cars table
insertCar(connection, "Toyota", "Camry", 2022, 25000.00);
insertCar(connection, "Honda", "Civic", 2023, 22000.00);
insertCar(connection, "Ford", "Mustang", 2021, 35000.00);
// Retrieving and displaying car information from the Cars table
displayCars(connection);
// Close the connection
connection.close();
} catch (Exception e) {
e.printStackTrace();
}
}
// Method to insert a car record into the Cars table
public static void insertCar(Connection connection, String brand, String model, int year, double price) throws
SQLException {
String sql = "INSERT INTO Cars (Brand, Model, Year, Price) VALUES (?, ?, ?, ?)";
PreparedStatement preparedStatement = connection.prepareStatement(sql);
preparedStatement.setString(1, brand);
preparedStatement.setString(2, model);
preparedStatement.setInt(3, year);
preparedStatement.setDouble(4, price);
int rowsInserted = preparedStatement.executeUpdate();
if (rowsInserted > 0) {
System.out.println("A new car record was inserted successfully.");
}
preparedStatement.close();
}
// Method to retrieve and display all car records from the Cars table
public static void displayCars(Connection connection) throws SQLException {
String sql = "SELECT * FROM Cars";
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(sql);
while (resultSet.next()) {
int carID = resultSet.getInt("CarID");
String brand = resultSet.getString("Brand");
String model = resultSet.getString("Model");
int year = resultSet.getInt("Year");
double price = resultSet.getDouble("Price");
System.out.println("Car ID: " + carID + ", Brand: " + brand + ", Model: " + model + ", Year: " + year + ", Price: "
+ price);
}
resultSet.close();
statement.close();
}
}
Servlet JSP
Servlet can accept all protocol requests. JSP only accepts HTTP requests.
In Servlet, we can override the service() method. In JSP, we cannot override its service() method.
It does not have inbuilt implicit objects. In JSP there are inbuilt implicit objects.
There is no method for running JavaScript on the While running the JavaScript at the client side in
client side in Servlet. JSP, client-side validation is used.
Packages are to be imported on the top of the Packages can be imported into the JSP program
program. (i.e, bottom , middleclient-side, or top )
The facility of writing custom tags is not present. The facility of writing custom tags is present.
22) Explain about various JSP Implicit Objects
A) JSP (JavaServer Pages) Implicit Objects are predefined objects that are automatically available to JSP pages
without needing to be explicitly declared or instantiated. These objects provide convenient access to various
components of the JSP environment, such as request, response, session, application, and more. Implicit
objects in JSP are accessible throughout the entire JSP page.
Here are the various implicit objects available in JSP:
request: This object represents the client's request to the server and provides access to parameters sent by the
client in the request. It allows JSP pages to retrieve form data, query parameters, and other information sent by
the client.
response: This object represents the server's response to the client and provides methods to set response
headers, status codes, and send content back to the client. It allows JSP pages to generate dynamic content to
be sent back to the client.
out: This object represents the output stream used to send content to the client. It is typically used to write
HTML content or other text-based data that will be included in the response sent to the client.
session: This object represents the user's session and provides access to session attributes, which are objects
stored on the server and associated with the user's session. It allows JSP pages to store and retrieve user-
specific data across multiple requests.
application: This object represents the servlet context or application context and provides access to
application-wide resources and configuration parameters. It allows JSP pages to share data and resources
across all users and sessions within the web application.
config: This object represents the configuration of the JSP page and provides access to initialization
parameters specified in the web deployment descriptor (web.xml). It allows JSP pages to retrieve configuration
settings specific to the current JSP page.
page: This object represents the current JSP page itself and provides access to various attributes and methods
related to the JSP page's execution environment. It allows JSP pages to perform operations such as forwarding
requests, including other resources, and accessing page-scoped attributes.
pageContext: This object represents the page context and provides access to all the other implicit objects, as
well as methods for managing page scope, request scope, session scope, and application scope attributes. It
serves as a bridge between JSP pages and the underlying servlet environment.
23) Develop a servlet code to illustrate the usage of getParameterValues() method of HTTPServletRequest
object?
A)import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class ParameterValuesServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,
IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
// Retrieve parameter values sent from the client
String[] hobbies = request.getParameterValues("hobby");
out.println("<!DOCTYPE html>");
out.println("<html>");
out.println("<head>");
out.println("<title>Parameter Values Example</title>");
out.println("</head>");
out.println("<body>");
out.println("<h2>Selected Hobbies:</h2>");
out.println("<ul>");
if (hobbies != null) {
// Display each selected hobby
for (String hobby : hobbies) {
out.println("<li>" + hobby + "</li>");
}
} else {
out.println("<li>No hobbies selected</li>");
}
out.println("</ul>");
out.println("</body>");
out.println("</html>");
}
}
24) Assume Products table in oracle database with following fields ( PID, Pname, Manufacturer, Price) a)
Create a HTML form that prompts the user to select a Manufacturer Name from a Drop down list along
with submit Button. b) Build Servlet code to display all the products manufactured by the manufacturer
selected by the user through HTML form?
A)<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Select Manufacturer</title>
</head>
<body>
<h2>Select Manufacturer</h2>
<form action="DisplayProductsServlet" method="post">
<label for="manufacturer">Select Manufacturer:</label>
<select id="manufacturer" name="manufacturer">
<option value="Manufacturer A">Manufacturer A</option>
<option value="Manufacturer B">Manufacturer B</option>
<option value="Manufacturer C">Manufacturer C</option>
<!-- Add more manufacturer options as needed -->
</select><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
DisplayProductsServlet.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.sql.*;
@WebServlet("/DisplayProductsServlet")
public class DisplayProductsServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
// Retrieve selected manufacturer from the form
String manufacturer = request.getParameter("manufacturer");
// JDBC Connection variables
String url = "jdbc:oracle:thin:@localhost:1521:XE"; // Oracle database URL
String username = "your_username";
String password = "your_password";
// SQL query to select products by manufacturer
String sql = "SELECT * FROM Products WHERE Manufacturer = ?";
// Establish database connection
try {
Class.forName("oracle.jdbc.driver.OracleDriver"); // Load Oracle JDBC driver
Connection conn = DriverManager.getConnection(url, username, password);
// Create PreparedStatement to execute SQL query
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setString(1, manufacturer);
// Execute the query
ResultSet rs = pstmt.executeQuery();
// Display product details
out.println("<h2>Products Manufactured by " + manufacturer + ":</h2>");
out.println("<ul>");
while (rs.next()) {
out.println("<li>" + rs.getString("Pname") + " - " + rs.getString("Price") + "</li>");
}
out.println("</ul>");
// Close ResultSet, PreparedStatement, and Connection
rs.close();
pstmt.close();
conn.close();
} catch (Exception e) {
out.println("<p>Error: " + e.getMessage() + "</p>");
}
}
}