Hi Friend,
Try the following code:
1)register.jsp:
<html>
<body>
<center><h3>Registration Form</h3></center>
<form method="get" action="Registration.jsp">
<center>
<table>
<tr><td>First Name:</td><td><input type="text" name="firstname" size="20"></td></tr>
<tr><td>Last Name:</td><td><input type="text" name="lastname" size="20"></td></tr>
<tr><td>User Name:</td><td><input type="text" name="username" size="20"></td></tr>
<tr><td>Password:</td><td><input type="password" name="password" size="20"></td></tr>
<tr><td>Address </td><td><input type="text" name="address" size="20"></td></tr>
<tr><td>Contact No </td><td><input type="text" name="contact" size="20"></td></tr>
<tr><td>Email: </td><td><input type="text" name="email" size="20"></td></tr>
<tr><td>City: </td><td><input type="text" name="city" size="20"></td></tr>
<tr><td>State: </td><td><input type="text" name="state" size="20"></td></tr>
<tr><td>Country: </td><td> <input type="text" name="country" size="20"></td></tr>
<tr><td><input type="submit" value="Submit" name="B1"></td><td><input type="reset" value="Reset" name="B2"></td></tr>
</table>
</center>
</form>
</body>
</html>
2)Registration.jsp:
<%@page import="java.sql.*" %>
<%
String fname= request.getParameter("firstname");
String lname= request.getParameter("lastname");
String uname= request.getParameter("username");
String pass= request.getParameter("password");
String address= request.getParameter("address");
String contact=request.getParameter("contact");
String email=request.getParameter("email");
String city=request.getParameter("city");
String state=request.getParameter("state");
String country=request.getParameter("country");
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:
mysql://localhost:3306/test","root";, "root");
Statement st=conn.createStatement();
int i=st.executeUpdate("insert into employee(firstname,lastname,username,password,email,address, contactNo,city,state,country) values ('"+fname+"','"+lname+"','"+uname+"','"+pass+"','"+email+"','"+address+"','"+contact+"','"+city+"','"+state+"','"+country+"')");
out.println("Data is successfully inserted");
%>
For the above code, we have created following database table:
CREATE TABLE `employee` (
`userid` bigint(30) NOT NULL auto_increment,
`firstname` varchar(40) default NULL,
`lastname` varchar(40) default NULL,
`username` varchar(40) default NULL,
`password` varchar(40) default NULL,
`email` varchar(100) default NULL,
`address` varchar(255) default NULL,
`contactNo` int(255) default NULL,
`city` varchar(255) default NULL,
`state` varchar(255) default NULL,
`country` varchar(255) default NULL,
PRIMARY KEY (`userid`)
)
Thanks