mysql - Please please help me with a javascript and servlet -


helllo guys.

i hope can me in here, because exam on wednesday, , thing missing before can go exam. quite new @ programming, excuse me if stupid question. right have servlet has connection mysql database. futheron have javascript. have 2 calendars can choose "from" date - "to" date. if fx pick 2014-03-06 - 2014-03-10 want have printed out how many hours have been working in time interval. means servlet getting column "allday_hours" mysql database. problem every time choose date javascript, returns hours allday_hours. means running through columns instead of dates have chosen.

can see have done wrong here? must javascript, or? hope guys can me?

have nice day/evening:-) julie

javascript:

  <form>         <input id="startdate"/>                              <input id="enddate"/>     </form>     <div id="startresult"></div>     <div id="endresult"></div>     <script>      $(function(){         $("#startdate").datepicker({             dateformat: 'yy-mm-dd',             onselect: function(datetext,inst){                 $('.selected-date').html(datetext);                  $.ajax({                       url: "../gethourssql",                       type: "post",                       data: json,                       success: function(data){                            start: $("#startdate").val();                           alert("success");                           $("#startresult").html(data);                        },                       error:function(){                           alert("failure");                           $("#startresult").html('there error while submit');                       }                       });             }         });     });      $(function(){             $("#enddate").datepicker({                 dateformat: 'yy-mm-dd',                 onselect: function(datetext,inst){                     $('.selected-date').html(datetext);                      $.ajax({                           url: "../gethourssql",                           type: "post",                           data: json,                           success: function(data){                               end: $("#enddate").val();                               alert("success");                               $("#endresult").html(data);                           },                           error:function(){                               alert("failure");                               $("#result").html('there error while submit');                           }                           });                 }             });         });  </script> 

servlet:

        package workpackage;  import java.io.*; import java.sql.*; import javax.servlet.*; import javax.servlet.annotation.webservlet; import javax.servlet.http.*;  @webservlet("/gethourssql") public class gethourssql extends httpservlet{      private static final long serialversionuid = 1l;      @override     protected void doget(httpservletrequest request, httpservletresponse response)             throws servletexception, ioexception {         dopost(request, response);     }      public void dopost(httpservletrequest req, httpservletresponse res)          throws servletexception, ioexception{          string connectionurl = "jdbc:mysql://localhost/nekiwork";         connection connection=null;          try {              class.forname("com.mysql.jdbc.driver");             connection = drivermanager.getconnection(connectionurl, "root", "");              string sql = "select *, (day_hours + (day_minutes / 60)) allday_hours workdata startdate='?' , enddate='?'";              preparedstatement pst = connection.preparestatement(sql);                 pst.setxxx(1,startdate);                 pst.setxxx(2,enddate);                  resultset rs = pst.executequery(sql);              float allday_hours_sum = 0;                 while (rs.next()){                                                           allday_hours_sum += rs.getfloat("allday_hours");                }                    res.setcontenttype("text/html;charset=utf-8");                           res.getwriter().print(allday_hours_sum);                  string startdate = req.getparameter("startdate");                 string enddate= req.getparameter("enddate");              pst.close();           }         catch(classnotfoundexception e){              system.out.println("couldn't load database driver: " + e.getmessage());         }         catch(sqlexception e){             system.out.println("sqlexception caught: " + e.getmessage());         }         catch (exception e){             system.out.println(e);         }         {              try {                 if (connection != null) connection.close();             }             catch (sqlexception ignored){                 system.out.println(ignored);             }         }     } } 

first of all, forgot send startdate&enddata javascript code servlet. can changing "data" member of ajax method argument.

also should request in servlet below

string startdate = req.getparameter("startdate"); string enddate= req.getparameter("enddate"); 

and should supply values inputs in preparedstatement.

pst.setxxx(1,startdate); pst.setxxx(2,enddate); 

i hope these information solve problem


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -