0% found this document useful (0 votes)
175 views7 pages

Worksheet - 3.2 - Java - Saikat Das

The document describes an experiment to create an online auction application using HTML, servlets, and a database. The code connects to an Oracle database using JDBC, executes a SQL query to retrieve employee records, and displays the results in an HTML table on the webpage. The servlet is mapped to the URL pattern "/display" in the web.xml file. When run, the servlet retrieves data from the database and displays it, demonstrating how to build a dynamic web application using Java servlets and JDBC to connect to a database.

Uploaded by

Saikat Das
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
175 views7 pages

Worksheet - 3.2 - Java - Saikat Das

The document describes an experiment to create an online auction application using HTML, servlets, and a database. The code connects to an Oracle database using JDBC, executes a SQL query to retrieve employee records, and displays the results in an HTML table on the webpage. The servlet is mapped to the URL pattern "/display" in the web.xml file. When run, the servlet retrieves data from the database and displays it, demonstrating how to build a dynamic web application using Java servlets and JDBC to connect to a database.

Uploaded by

Saikat Das
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Experiment -3.

Student Name: Saikat Das UID: 20BCS6818

Branch: CSE_AIML 2B Section/Group: B

Semester: 4th Date of Performance: 08/05/2022

Subject Name: PROJECT BASED LEARNING IN JAVA LAB


Subject Code: 22E-20CSP-287

Aim/Overview of the practical:


Create an application for Online Auction using HTML and Servlet. Use
database to store and retrieve record.

CODE:
import java.io.*;

import javax.servlet.*;

import javax.servlet.http.*;
import java.sql.*;

public class display extends HttpServlet

public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException

PrintWriter out = res.getWriter();

res.setContentType("text/html");

out.println("<html><body>");

try

{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

Connection con = DriverManager.getConnection("jdbc:odbc:mydsn", "system", "pintu");

// Here dsnname- mydsn,user id- system(for oracle 10g),password is pintu.

Statement stmt = con.createStatement();

ResultSet rs = stmt.executeQuery("select * from employee");

out.println("<table border=1 width=50% height=50%>");

out.println("<tr><th>EmpId</th><th>EmpName</th><th>Salary</th><tr>");

while (rs.next())

String n = rs.getString("empid");

String nm = rs.getString("empname");
int s = rs.getInt("sal");

out.println("<tr><td>" + n + "</td><td>" + nm + "</td><td>" + s + "</td></tr>");

out.println("</table>");

out.println("</html></body>");

con.close();

catch (Exception e)

out.println("error");

}
}

web.xml setting:-

<?xml version="1.0" encoding="ISO-8859-1"?>

<!--

<servlet>

<servlet-name>display</servlet-name>

<servlet-class>display</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>display</servlet-name>

<url-pattern>/display</url-pattern>

</servlet-mapping>

</web-app>

Result/Output/Writing Summary:

Compile:-
Running the servlet in a web browser:-
11. Graphs (If Any): Image /Soft copy of graph paper to be attached here

Evaluation Grid (To be created as per the SOP and Assessment guidelines by the faculty):

Sr. No. Parameters Marks Obtained Maximum Marks


1.
2.
3.

You might also like