Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Other Java > Java Databases
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Java Databases Discussion specific to working with Java Databases. For other Java topics, please see related Java forums. For database discussions not specific to Java, please see the Database category.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java Databases section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old December 17th, 2007, 07:05 PM
Registered User
 
Join Date: Dec 2007
Location: , , Finland.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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>

Reply With Quote
  #2 (permalink)  
Old December 24th, 2007, 05:08 AM
Friend of Wrox
 
Join Date: Mar 2007
Location: Hyderabad, A.P., India.
Posts: 373
Thanks: 0
Thanked 1 Time in 1 Post
Default

Little exception trace would be helpful to identify the problem.


- Rakesh
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Accessing MySql db from a Servlet(Urgent) balarkavelidi Apache Tomcat 1 January 15th, 2006 09:03 AM
Updating DB abbylee26 Classic ASP Databases 15 March 17th, 2004 05:21 AM
updating db with dataAdapter/dataTable problem mm1234 ADO.NET 0 November 19th, 2003 05:49 AM
Updating an Access DB stu9820 ASP.NET 1.0 and 1.1 Basics 1 September 30th, 2003 01:09 PM
ASP: Textarea Problem when updating DB seala Access ASP 1 June 13th, 2003 12:35 PM



All times are GMT -4. The time now is 09:52 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.