You are not logged in. Please login at to post your questions!


how to store date from datepicker of jsp via servlet in derby database?


<%@page contentType="text/html" pageEncoding="UTF-8"%> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href=""> <title>reservation Page</title>
    <link rel="stylesheet" href="//">
    <!--<link rel="stylesheet" href="/resources/demos/style.css">-->
    <script src=""></script>
    <script src=""></script>

        $(function () {



  <input type="text" class="form-control" name="datepicker" id="datepicker" placeholder="Date" required=""/>
  <input type="text" class="form-control" name="time"  id="timepicker" placeholder="Time" required=""/>

  <select id="party" name="noOfparty" placeholder="Number of Party" class="form-control" required="">
                    <option>Number of Party</option> 

  <button class="btn btn-lg btn-primary btn-block"  name="Submit" value="reserve" type="Submit"> Reserve 


package Servlet;

import; import; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.text.ParseException; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse;

public class ReserveServlet extends HttpServlet {

private static final long serialVersionUID = 1L;

//private static final Date Date = null;
public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    PrintWriter out = response.getWriter();

   // String dateString = request.getParameter("date");
    //Date Date = request.getParameter("picker");

    String date = request.getParameter("datepicker");

    //java.text.DateFormat df = new java.text.SimpleDateFormat("MM/dd/yyyy");
    java.text.DateFormat format = new java.text.SimpleDateFormat("MM/dd/yyyy");
    try {
        //java.util.Date d = df.parse(Date);
        java.util.Date da = format.parse(date);
    } catch (ParseException ex) {
        //Logger.getLogger(ReserveServlet.class.getName()).log(Level.SEVERE, null, ex);

    String Time = request.getParameter("time");
    int party = Integer.parseInt(request.getParameter("noOfparty"));

    try {
        System.out.println("driver loaded");

        Connection con = DriverManager.getConnection("jdbc:derby://localhost:1527/test", "test", "test");
        System.out.println("connection success");

        PreparedStatement ps = con.prepareStatement("insert into reserve values(?,?,?)");
        System.out.println("values inserted");

        //ps.setDate(1, Date);
        java.sql.Date da= new java.sql.Date(da.getTime());
        ps.setDate(1, da);
        ps.setString(2, Time);
        ps.setInt(3, party);

        int i = ps.executeUpdate();
        if (i > 0) {
            out.print("Your Table is successfully reserved...");

    } catch (Exception e2) {



asked 19 Aug '17, 02:22

darshana40's gravatar image

accept rate: 0%

toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:


question asked: 19 Aug '17, 02:22

question was seen: 1,231 times

last updated: 19 Aug '17, 02:22