title: How to send date and time to SQL using java
body: <p>I am calling a stored procedure in a database.
  Two of its parameters requires date and time in sql date format.</p>
  
  <pre><code>String x = new SimpleDateFormat("MM-dd-yyyy").format(new Date()) + " 00:00:00 AM";
  String y = new SimpleDateFormat("MM-dd-yyyy").format(new Date()) + " 11:59:00 PM";
  Date fromDate = null;
  Date toDate = null;
  try {
     fromDate = new SimpleDateFormat("MM-dd-yyyy HH:mm:ss a").parse(x);
     toDate = new SimpleDateFormat("MM-dd-yyyy HH:mm:ss a").parse(y);
  } catch (ParseException ex) {
  }
  CallableStatement proc_stmt = con.prepareCall("{ call someproc(?,?) }");
  proc_stmt.setDate(1, (java.sql.Date) fromDate);
  proc_stmt.setDate(2, (java.sql.Date) toDate);
  </code></pre>
  
  <p>I believe if i send just the date(excluding time), the code works, but its of no use to me as the database does not generate correct results.
  When i run the above code I get            </p>
  
  <pre><code>ClassCastException:java.util.Date cannot be cast to java.sql.Date
  </code></pre>
  
  <p>Any solution?</p>