Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
7 views5 pages

Practical 1

The document outlines the creation of a registration servlet in Java using JDBC to accept user details such as username, password, email, and mobile through an HTML form. It includes the HTML form structure and the Java servlet code that processes the form data and stores it in a MySQL database. The servlet uses a prepared statement to insert the data into the database and handles exceptions during the process.

Uploaded by

fannyskylark2003
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)
7 views5 pages

Practical 1

The document outlines the creation of a registration servlet in Java using JDBC to accept user details such as username, password, email, and mobile through an HTML form. It includes the HTML form structure and the Java servlet code that processes the form data and stores it in a MySQL database. The servlet uses a prepared statement to insert the data into the database and handles exceptions during the process.

Uploaded by

fannyskylark2003
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/ 5

Practical 1

C) Create a registration servlet in java using JDBC.Accept


the detail such as username,password,email,mobile from
the user using HTML form.and store the registration details
in database.

Index.html
Enter Name:
Enter Password:
Enter email:
Enter mobile:
Submit

<html>

<form action="reg" method="get">

Enter Name: <input type="text" name="t1"><br>

Enter Password: <input type="text" name="t2"><br>

Enter email: <input type="text" name="t3"><br>

Enter mobile: <input type="text" name="t4"><br>

<input type="submit" name="save">

</form>

</html>
Creating a Servlet having name reg.java

reg.java
package com.demo;

import java.io.IOException;

import java.io.PrintWriter;

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 java.sql.*;

@WebServlet(name = "reg", urlPatterns = {"/reg"})

public class reg extends HttpServlet

protected void doGet(HttpServletRequest request, HttpServletResponse


response) throws ServletException, IOException

PrintWriter out=response.getWriter();

String name=request.getParameter("t1");

String pass=request.getParameter("t2");

String email=request.getParameter("t3");

String mobile=request.getParameter("t4");

try
{

Class.forName("com.mysql.jdbc.Driver");

Connection
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/student","admi
n","nilam");

PreparedStatement pst=con.prepareStatement("insert into info values(?,?,?,?)");

pst.setString(1,name);

pst.setString(2,pass);

pst.setString(3,email);

pst.setString(4,mobile);

int row=pst.executeUpdate();

out.println("<h1>"+row+"inserted record successfully!!!!");

catch(Exception ex)

out.println(ex);

}
Output

You might also like