problem with updating the db using servlet
Hi,
I have a college project and am facing some problems. I have a CONTROLLER CLASS holding all the logic, a SERVLET and a JSP page for showing errors. The prob is that I cant call a certain method from the servlet.. Here is the method I want to call from the servlet. And the problem area in the servlet is marked in red, except these two things, everything is working fine. PLEASE HELP
*******************part of participantDAO class*******************
public boolean updateParticipantTime (String tfNumber, String tfTime) throws Exception
{
Connection dbConnection;
Statement statement;
ResultSet resultSet;
String sqlText="";
boolean update = false;
Vector <Participant> myVector = new Vector <Participant>();
Participant participant;
if (jdbcDriverLoaded == false)
loadDriver();
try
{
dbConnection = DriverManager.getConnection (connectionString) ;
statement = dbConnection.createStatement () ;
int number = Integer.parseInt(tfNumber.trim());
if(tfTime.equals("") || tfTime == null)
{
sqlText = "UPDATE participant SET finishingTime = NULL WHERE number = " + number ;
System.out.println (sqlText) ;
statement.executeUpdate (sqlText) ;
sqlText = "n/a" ;
statement.close () ;
dbConnection.close () ;
update = true;
}
else
{
sqlText = "UPDATE participant SET finishingTime = " +tfTime.trim()+"WHERE number = "+ number ;
System.out.println (sqlText) ;
statement.executeUpdate(sqlText) ;
sqlText = "n/a" ;
statement.close () ;
dbConnection.close () ;
update = true;
}
}
catch (SQLException sqle)
{
printSQLException (sqle, sqlText) ;
throw sqle ;
}
return(update);
}
*********************SERVLET********************** ****
import javax.servlet.* ;
import javax.servlet.http.* ;
import java.io.* ;
import Participant_package.*;
import java.lang.*;
public class UpdateTimeServlet extends HttpServlet
{
public boolean updateTime = false;
ParticipantDAO participantDAO = new ParticipantDAO();
int intNum;
/**
* @param request <code>HttpServletRequest</code>
* @param response <code>HttpServletResponse</code>
*
*/
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
doPost(request, response);
}
/**
* @param request <code>HttpServletRequest</code>
* @param response <code>HttpServletResponse</code>
*
*/
public void doPost (HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
try
{
HttpSession session = request.getSession(true);
String number = null;
String time = null;
String messageText = "";
number = request.getParameter("tfNumber");
time = request.getParameter("tfTime");
if(number.equals(""))
{
messageText="Please give participant number.";
request.setAttribute("message", messageText);
RequestDispatcher dispatcher = request.getRequestDispatcher("/jsp/UpdateTime.jsp");
dispatcher.forward(request, response);
}
else
{
intNum = Integer.parseInt(number);
if(participantDAO.existParticipant(number) == false)
{
messageText="No such participant was found. Try again!";
request.setAttribute("message", messageText);
RequestDispatcher dispatcher = request.getRequestDispatcher("/jsp/UpdateTime.jsp");
dispatcher.forward(request, response);
}
else
{
participantDAO.updateParticipantTime(number, time);
messageText="Update successful";
request.setAttribute("message", messageText);
RequestDispatcher dispatcher = request.getRequestDispatcher("/jsp/UpdateTime.jsp");
dispatcher.forward(request, response); }
}
}
catch (Exception e)
{
System.out.println ("********** TIME FORMAT ERROR *********") ;
System.out.println ("An unexpected exception occurred:" + e) ;
System.out.println("Try again once more!");
nextPage("/jsp/UpdateTime.jsp", request, response);
return; }
}
/**
* Forwards according to the URI argument
*
* @param request <code>HttpServletRequest</code>
* @param response <code>HttpServletResponse</code>
* @param nextURL <code>String</code>
*/
private void nextPage (String nextURI, HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
request.getRequestDispatcher(nextURI).forward(requ est, response) ;
}
}
**********************JSP PAGE***************************
<%@ page import = "java.util.*" %>
<?xml version = "1.0" encoding="ISO-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<link rel ="stylesheet" type="text/css" href="/atk84f/CSS/RaceStyle.css" />
<title>
Update participants finishing time
</title>
</head>
<body>
<img src ="/atk84f/images/running1.jpg" />
<a href="http://validator.w3.org/check?uri=referer"><img
src="http://www.w3.org/Icons/valid-xhtml11-blue"
alt="Valid XHTML 1.1" height="31" width="88" /></a>
<br />
<br />
<br />
<br />
<br />
<br />
<h2>Update finishing time</h2>
<%
String number = (String) request.getParameter("tfNumber");
String time = (String) request.getParameter("tfTime");
String messageText = (String)request.getAttribute ("message") ;
if(number == null)
number = "";
if(time == null)
time="";
if(messageText == null)
messageText = "";
%>
<form action ="/atk84f/servlet/UpdateTimeServlet" method="post">
<br />
<table>
<tr>
<td class="form">Participant Number: </td>
<td class="form"><input type="text" name="tfNumber" value="<%=number%>" /></td>
</tr>
<tr class=""tr>
<td class="form">Time (hh:mm:ss): </td>
<td class="form"><input type="text" name="tfTime" value="<%=time%>" /></td>
</tr>
<tr class="tr">
<td class="form"></td>
<td class="form"><input type="submit" name="btSubmit" value="Update" /></td>
</tr>
</table>
</form>
<p><big><%= messageText %></big></p>
<p><a href ="/atk84f/Race.html">Main page</a></p>
<p><a href ="/atk84f/jsp/ParticipantList.jsp">List of the participants</a><p>
</body>
</html>
|