Saurav 3.2 Java

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Experiment: 3.

Student Name: Manish UID: 21BCS10920


Branch: CSE Section/Group: 801 A
Semester: 6th Date of Performance: -04-24
Subject Name: Java Lab Subject Code: 21CSH-319

1. Aim-
Create an application for Online Auction using HTML and Servlet. Use the database to store and
retrieve records.
2. Objective –
Create a HTML Page, connect it to JDBC server and save information using servlets

3.Algorithm:
(a).
1. Turn On XAMPP Server
2. Create a New Database and a new table inside the Database
3. Add all the required Attribute fields

(b).
1. Build a HTML page with fields to fetch data and connect to Servlets
2. Inside Eclipse, create a new class inside the project
3. Built a connection with the mySQL Server
4. Using Prepared Statements Fetch information to and fro from the table.

4.Source Code:
Auction.html
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="Auction_data" method="post">
Name:<input type="text" name="userName"/><br/><br/>
Product:
<select name="productName">
<option>Dell</option>
<option>HP</option>
<option>Sony</option>
<option>Lenevo</option>
</select>
<br/><br/>

Bid Value:<input type="text" name="bidValue"/><br/><br/>


</form> <input type="submit" value="register"/>
</body>

</html>

Auction_data.java

import java.io.IOException;
import java.io.PrintWriter; import
java.sql.Connection; import
java.sql.DriverManager;
import java.sql.PreparedStatement; import java.sql.ResultSet;
import java.sql.Statement;
import javax.servlet.ServletException; import
javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest; import
javax.servlet.http.HttpServletResponse;
public class Auction_data extends HttpServlet { private static
final long serialVersionUID = 1L;

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws


ServletException, IOException
{ response.setContentType("text/html"
); PrintWriter out = response.getWriter();

String
n=request.getParameter("userName"); String
p=request.getParameter("productName"); int
e=Integer.parseInt(request.getParameter("bidValue"));

try
{
Class.forName("com.mysql.jdbc.Dri ver");
Connection

con=DriverManager.getConnection("jdbc:mysql://localhost:3 306/test","root",""); Statement


stmt=con.createStatement();
PreparedStatement ps=con.prepareStatement("insert into user values(?,?,?)");
ps.setString(1,n); ps.setString(2,p
);
ps.setInt(3,e);

"+rs.getInt(3));

con.close();
}

catch (Exception e2)


{
System.out.println(e2);
} out.close();
}
}
5.Output:-
3. Learning Outcomes:-
• Learn about concept of File Handling in java.
• Learn about LinkedList, Exception Handling in java.

You might also like