I have an HTML form where I have a date and a time picker. What I am trying to do is get the date and time by `request.getParameter` in servlet, then insert it into my database. How can I get that date and time in date and time format or get them as a string then parse them.

Code:

```
String[] quantity = request.getParameterValues("Quantity_field");
     java.util.Date selectedDate = new SimpleDateFormat("yyyy-MM-dd").parse(request.getParameter("deliveryDate")); //using this one i am trying to get date but it is showing error
    java.util.Date selectedTime = new SimpleDateFormat("hh:mm:ss").parse(request.getParameter("deliveryTime")); 
    System.out.println(selectedDate);
    java.util.Date dateUtil = new Date();
    java.sql.Date dateSql = new java.sql.Date(dateUtil.getTime());
    java.sql.Timestamp timestamp = new Timestamp(dateUtil.getTime());

    try {
        con = DBConnection.createConnection();
        statement = con.createStatement();
        String query = " insert query  VALUES   (?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
        PreparedStatement ps = con.prepareStatement(query);
        for (int i = 0; i < quantity.length; i++) {
            if (Double.parseDouble(quantity[i]) != 0) {
                if(recorderNo!=0)
                {
                    ps.setInt(1, recorderNo);
                }
                else
                {
                    ps.setInt(1, 1);
                }

                ps.setDate(2, dateSql);
                ps.setString(3, 77);
                ps.setDouble(4, 55);
                ps.setInt(5, 0);
                ps.setInt(6, 0);
                ps.setDouble(7, Double.parseDouble(quantity[i]));
                ps.setInt(8, 0);
                ps.setInt(9, 0);
                ps.setInt(10, 0);
                ps.setString(11, outlet);
                ps.setTimestamp(12, timestamp);
                 ps.setDate(13,selectedDate); // here i am trying to put date
                ps.setTime(14,selectedTime);// and here time
                ps.addBatch();
            }
        }
        ps.executeBatch();

```

I found this on Google to get date and time but its throwing error at:

```
ps.setDate(13,selectedDate);
ps.setTime(14,selectedTime);

```

The error is: 

> 
> The method setDate(int, java.sql.Date) in the type PreparedStatement is not applicable for the arguments (int, java.util.Date)
> 
> 
> 

**Edit**

i am doing like this

```
java.util.Date selectedDate = new SimpleDateFormat("yyyy-MM-dd").parse(request.getParameter("deliveryDate")); 
    java.util.Date selectedTime = new SimpleDateFormat("hh:mm:ss").parse(request.getParameter("deliveryTime"));
    java.sql.Date dateSelected = new java.sql.Date(selectedDate.getTime());     
    java.sql.Time dateTime=new Time(selectedTime.getTime());

```

but the above lines are throwing error, i think i am missing something or writing something wrong