I have jsp class and the servlet it's seem like it's working ok exceptton for the combo box in jsp i don't know how call it to enter database. I am using access database. help me please
this is my jsp
<!-- Initialize the bean for use in page processing. -->
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body onLoad="document.shiftForm
.shiftName
.onchange(
)">
<form name = "send" action ="InsertServlet " method ="post">
<form name="shiftForm">
<table width="42%" border="0">
<tr>
<td width="19%"> </td>
<td width="30%">
<p> </p></td>
<td width="8%"> </td>
<td width="43%"> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td>Days</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>Shift name
<p><select name="shiftName" onChange="redirect(this)">
<option value="Morning">Morning</o
ption>
<option value "Afternoon">Afternoon</opt
ion>
<option value ="Night">Night</option>
</select>
<p> StartTime
<select name="shiftStart" onChange="this.form.shiftL
ength.onch
ange()">
</select>
<script>
<!--
var shiftTimes = [
["7:00AM","7:30AM","8:00AM
","8:30AM"
,"9:00AM",
"9:30AM","
10:00AM","
10:30AM","
11:00AM","
11:30AM","
12:00AM"],
["12:30PM","1:00PM","1:30P
M","2:00PM
","2:30PM"
,"3:00PM",
"3:30PM","
4:00PM","4
:30PM","5:
00PM","5:3
0PM","6:00
PM"],
["6:30PM","7:00PM","7:30PM
","8:00PM"
,"8:30PM",
"9:00PM","
9:30PM","1
0:00PM","1
0:30PM","1
1:00PM","1
1:30PM","1
2:00PM"]];
function redirect(theSel){
opt = theSel.form.shiftStart.opt
ions;
opt.length=0;
shiftOpt = shiftTimes[theSel.selected
Index];
for (i=0;i<shiftOpt.length;i++
){
opt[i] = new Option(shiftOpt[i], shiftOpt[i])
}
opt[0].selected=true;
theSel.form.shiftStart.onc
hange();
}
function setShiftEnd(theField){
var sTime = new Date("1/1/2000 "+theField.form.shiftStart
.value)
var aDur = theField.value.split(":");
sTime.setHours(sTime.getHo
urs()+aDur
[0]*1);
if(aDur[1]) sTime.setMinutes(sTime.get
Minutes()+
aDur[1]*1)
;
HH = sTime.getHours();
MM = sTime.getMinutes();
if(MM<10) MM = "0"+MM;
if(HH<13) {
AP = " AM";
} else {
HH = HH - 12;
AP = " PM";
}
theField.form.shiftEnd.val
ue = HH+":"+MM+AP;
}
function go(){
var temp=document.shiftForm.sh
iftStart;
location=temp.options[temp
.selectedI
ndex].valu
e
}
//-->
</script>
<td>Mon
<td>
<input name="mondayCheck" type="checkbox" id="mondayCheck" value="Monday" checked />
<tr>
<td> </td>
<td><p>Shift Length</p>
<input type="text" name="shiftLength" onChange="setShiftEnd(this
)"> hours
<p> </p></td>
<td>Tues</td>
<td>
<input name="tuesdayCheck" type="checkbox" id="tuesdayCheck" value="Tuesday" checked >
</td>
</tr>
<tr>
<td> </td>
<td><p>EndTime</p>
<p>
<input type="text" name="shiftEnd" value="">
</p></td>
<td>Wed</td>
<td>
<input name="wednesdayCheck" type="checkbox" id="wednesdayCheck" checked >
</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td>Thurs</td>
<td>
<input name="thursdayCheck" type="checkbox" id="thursdayCheck" value="Thursday" checked >
</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td>Frid</td>
<td>
<input name="fridayCheck" type="checkbox" id="fridayCheck" value="Friday" checked >
</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td>Sat</td>
<td>
<input name="saturdayCheck" type="checkbox" id="saturdayCheck" value="Saturday" checked >
</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td>Sun</td>
<td>
<input name="sundayCheck" type="checkbox" id="sundayCheck" value="Sunday" checked >
</td>
</tr>
<tr>
<td> </td>
<td>
<input type="submit" name="Submit" value="Send">
</td>
<td> </td>
<td> <input type="submit" name="Submit2" value="Back"></td>
</tr>
</table>
</form>
</form>
<p> </p>
</body>
</html>
this is my servlet
import java.sql.*;
import java.io.*;
import javax.servlet.*;
import java.util.*;
import javax.servlet.http.*;
public class InsertServlet extends HttpServlet
{
static final int MS_ACCESS_DUP_KEY = 0;
private Statement statement = null;
private Connection connection = null;
private String URL = "jdbc:odbc:roster"; // The ODBC DSN is hard-coded.
private boolean jdbcDriverError = false, sqlError = false;
private PrintWriter output;
public void init(ServletConfig config) throws ServletException
{
super.init(config);
try
{
Class.forName("sun.jdbc.od
bc.JdbcOdb
cDriver");
connection = DriverManager.getConnectio
n(URL, "", "");
}
catch(ClassNotFoundExcepti
on cfne)
{
System.err.println("Failed
to load JDBC/ODBC driver.");
jdbcDriverError = true;
}
catch(SQLException sqle)
{
System.err.println("Unable
to connect! - " +
"Check the connection string");
sqlError = true;
}
return;
}
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
String shiftName,shiftStart,shift
End,mon,tu
e,wed,thur
s,frid,sat
,sun;
output = res.getWriter();
if(sqlError)
output.println("<h2>Fatal error using DSN to connect to database. " +
"Please advise your leader.</h2>");
else
{
if(jdbcDriverError)
output.println("<h2>Fatal error loading Java database driver. " +
"Please advise your leader.</h2>");
else
{
shiftName = req.getParameter("shiftNam
e");
shiftStart = req.getParameter("shiftSta
rt");
shiftEnd = req.getParameter("shiftEnd
");
mon = req.getParameter("mondayCh
eck");
tue = req.getParameter("tuesdayC
heck");
wed = req.getParameter("wednesda
yCheck");
thurs = req.getParameter("thursday
Check");
frid = req.getParameter("fridayCh
eck");
sat = req.getParameter("saturday
Check");
sun = req.getParameter("sundayCh
eck");
res.setContentType("text/h
tml");
/* Note: The GuestBook database also contains fields Street,
* Suburb, State and Post Code that are not used in this example.
* However, the insert into the database must still account for
* these fields.
*/
boolean success = insertIntoDB("'" +
shiftName + "','" +
shiftStart + "','" +
// Next one includes the 4 unused (by this servlet) fields.
shiftEnd + "','" +
(mon != null ? "yes" : "no") + "','" +
(tue != null ? "yes" : "no") + "','" +
(wed != null ? "yes" : "no") + "','" +
(thurs != null ? "yes" : "no") + "','" +
(frid != null ? "yes" : "no") + "','" +
(sat != null ? "yes" : "no") + "','" +
(sun != null ? "yes" : "no") + "'");
if(success)
output.print("<h2><font face = \"Arial\">Thank you, " + shiftName +
", for registering.</font></h2>")
;
}
}
output.close();
return;
}
private boolean insertIntoDB(String stringToInsert)
{
try
{
statement = connection.createStatement
();
statement.executeUpdate("I
NSERT INTO EmpAvai values (" +
stringToInsert + ");");
statement.close();
}
catch(SQLException sqle)
{
int dbErrorCode = sqle.getErrorCode();
if(dbErrorCode == MS_ACCESS_DUP_KEY)
output.print("<h2>ERROR: Your email address already exists" +
" - please choose another!</h2>");
else
output.print("<h2>ERROR: Problems with adding new entry.</h2>");
return false;
}
return true;
}
public void destroy()
{
try
{
if(connection != null)
connection.close();
}
catch(SQLException sqle)
{
// Messages to System.out and System.err appear on the server's
// console window.
System.err.println("Proble
m closing the database");
}
}
}