By:
NicheTech
http://www.nichetechinstitute.com/
©NicheTech Computer Solutions Pvt ltd
Demo Example for Insert records
in Servlet
Login.jsp
<html>
<head>
</head>
<title>Login</title>
<body>
<form name="Login_form“ action=“Login" method="post">
User Name <input type="text" name="UserName" />
<br />
Password <input type="password" name=“pwd" /><br />
<input type="submit" name="sSubmit" value="Submit" />
</form>
</body>
</html>
connectivityClaas.java
//Required import packages
import java.io.*;
import java.util.*;
import javax.sql.*;
import javax.servlet.*;
import javax.servlet. Http.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
//class Nmae Declration
 public class connectivityClaas extends HttpServlet
 {
// connecting to database object
Connection cn = null;
PreparedStatement pst
try {
Class.forName("com.mysql.jdbc.Driver");
con =DriverManager.getConnection
(“localhost/Testexample", "root","root");
String username = req.getParameter(“UserName");
String fname = req.getParameter(“pwd");
stmt = con.createStatement();
String sql ="insert into login values (?,?)";
pst = connection.prepareStatement(sql);
int numRowsChanged = pst.executeUpdate();
if(numRowsChanged==true)
{
out.println(“Successful Inserted”);
}else
{
out.println(“Faild to Inserted”);
}
} catch (Exception){}
}
Thanks
 NicheTech Com Sol Pvt Ltd
 Our Sites
1) http://www.nichetechsolutions.com/
(Development)
2) http://www.nichetechinstitute.com/ (NicheTech
Gurukul)
3) http://www.liveprojecttraining.in/ ( Live Project
Training Details)
4) https://www.facebook.com/nichetechinstituteIndi
a ( For Daily Updates)

Java Training Ahmedabad , how to Insert Data in Servlet, iOS Classes Ahmedabad