
I got problem in sending values from servlet . * i am using ms acces * i cant display my values but der is increase in number of rows
my jsp:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<!-- used jquery for datepicker -->
<meta charset="utf-8" /> <title>register</title> <link rel="stylesheet" href="css/jquery-ui[1].css" /> <script src="script/jquery-1.8.2.js"></script> <script src="http://code.jquery.com/ui/1.9.0/jquery-ui.js"></script> <link rel="stylesheet" href="/resources/demos/style.css" /> <script> $(function() { $( "#datepicker" ).datepicker(); }); </script>
</head>
<body background="images/register.bmp">
<div id="container" style="height:500px;width:500px">
<div id="login" style="background-color:#FAEBD7;height:500px;width:350px;float:left;">
<center><h2><i><b>Registration</b></i></h2></center>
<table>
<tr>
<td><b><i>Username</i></b></td>
<td><input type="text" size="15" maxlength="30" name="username" /></td>
</tr>
<tr>
<td ><b><i>Last Name</i></b></td>
<td><input type="text" size="15" maxlength="30" name="lastname" ></td>
</tr>
<tr>
<td ><b><i>Email</i></b></td>
<td><input type="text" size="15" maxlength="30" name="email" ></td>
</tr>
<tr>
<td ><b><i>Re-enter Email</i></b></td>
<td><input type="text" size="15" maxlength="30" name="reemail" ></td>
</tr>
<tr>
<td ><b><i>New Password</i></b></td>
<td><input type="password" size="15" maxlength="30" name="newpass" ></td>
</tr>
<tr>
<td ><b><i>Gender</i></b></td>
<td><select name="gender">
<option value="male">male</option>
<option value="female">female</option>
</select></td>
</tr>
<tr>
<td ><b><i>DOB</i></b></td>
<td>
<input type="text" id="datepicker" name="datepicker" />
</td>
</tr>
<tr>
<form action="./Registartion" method="post">
<input type="submit" value="SINGUP"></input>
</form>
<!-- <td><INPUT TYPE="button" VALUE="SIGNUP" onClick="parent.location='page1.html'"></td>-->
</tr>
</table>
</div>
</div>
</body>
</html>
registration servlet:
package validate;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
/**
* Servlet implementation class Registartion
*/
public class Registartion extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public static String username="";
public static String lastname="";
public static String email="";
public static String reemail="";
public static String newpass="";
public static String gender="";
public static String datepicker="";
public static void main(String[] args) {
Connection con = null;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=C:\\myca\\demo\\authors.accdb");
// Creating a database table
Statement sta = con.createStatement();
int i=sta.executeUpdate("insert into registration (username,lastname,email,reemail,password,gender,dob) values('"+username+"','"+lastname+"','"+email+"','"+reemail+"','"+newpass+"','"+gender+"','"+datepicker+"')");
System.out.println("Data is successfully inserted!");
sta.close();
con.close();
} catch (Exception e) {
System.err.println("Exception: "+e.getMessage());
}
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
username=request.getParameter("username");
lastname=request.getParameter("lastname");
email=request.getParameter("email");
reemail=request.getParameter("reemail");
newpass=request.getParameter("newpass");
gender=request.getParameter("gender");
datepicker=request.getParameter("datepicker");
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
}
please help in issue

Insert form data into MS database
Follow these steps:
1)Go to the start->Control Panel->Administrative Tools-> data sources.
2)Click Add button and select the driver Microsoft Access Driver(*.mdb).
3)After selecting the driver, click finish button.
4)Then give Data Source Name and click ok button.
5)Your DSN will get created.
6) Restart your server and run your jsp/servlet code.
1)form.jsp:
<html>
<body>
<form method="POST" action="../ServletForm">
<pre>
User Id: <input type="text" name="userId" size="20"></p>
First Name: <input type="text" name="firstname" size="20"></p>
Surname: <input type="text" name="surname" size="20"></p>
Address1: <input type="text" name="address1" size="20"></p>
Address2: <input type="text" name="address2" size="20"></p>
Town: <input type="text" name="town" size="20"></p>
City: <input type="text" name="country" size="20"></p>
Zip code: <input type="text" name="zipcode" size="20"></p>
<input type="submit" value="Submit" name="B1"></p>
</pre>
</form>
</body>
</html>
2)ServletForm.data:
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class ServletForm extends HttpServlet{
public void init(ServletConfig config) throws ServletException{
super.init(config);
}
public void doPost(HttpServletRequest req,
HttpServletResponse res) throws ServletException,
IOException{
ResultSet rs;
res.setContentType("text/html");
PrintWriter out = res.getWriter();
String uId = req.getParameter("userId");
String fname = req.getParameter("firstname");
String sname = req.getParameter("surname");
String address1 = req.getParameter("address1");
String address2 = req.getParameter("address2");
String town = req.getParameter("town");
String county = req.getParameter("country");
String zipcode = req.getParameter("zipcode");
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn =DriverManager.getConnection("jdbc:odbc:access");
String sql = "insert into emp_details values (?,?,?,?,?,?,?,?)";
PreparedStatement pst = conn.prepareStatement(sql);
pst.setString(1, uId);
pst.setString(2, fname);
pst.setString(3, sname);
pst.setString(4, address1);
pst.setString(5, address2);
pst.setString(6, town);
pst.setString(7, county);
pst.setString(8, zipcode);
int numRowsChanged = pst.executeUpdate();
out.println(" Hello : ");
out.println(" '"+fname+"'");
pst.close();
}
catch(ClassNotFoundException e){
out.println("Couldn't load database driver: "
+ e.getMessage());
}
catch(SQLException e){
out.println("SQLException caught: "
+ e.getMessage());
}
catch (Exception e){
out.println(e);
}
finally {
try {
if (connection != null) connection.close();
}
catch (SQLException ignored){
out.println(ignored);
}
}
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.