Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For most of the scenario you need <code>java.util.Date</code> and not <code>java.sql.Date</code></p> <p>From the <a href="http://docs.oracle.com/javase/1.5.0/docs/api/java/sql/Date.html#valueOf%28java.lang.String%29" rel="nofollow">documentation</a> of <code>java.sql.Date</code></p> <blockquote> <p>Throws: IllegalArgumentException - if the date given is not in the JDBC date escape format (yyyy-mm-dd)</p> </blockquote> <p>which means date coming from jsp is not in the form of <code>yyyy-mm-dd</code> format. </p> <p>If you are going to use java.sql.Date object then format the incoming date to <code>yyyy-mm-dd</code> format before using <code>valueOf</code> API. </p> <p>For conversion you can use <code>SimpleDateFormat</code> to format your incoming value to <code>yyyy-mm-dd</code>.</p> <p>Edit:</p> <p>Even better instead of using Date object you should <a href="http://docs.oracle.com/javase/6/docs/api/java/util/Calendar.html" rel="nofollow">Calendar</a> for most of the operation.</p> <p>Edit:</p> <p>As per comments:</p> <p>Assuming my Incoming date from JSP is dd-MMM-yyyy format. </p> <pre><code>try { String date = "25-Apr-2012"; SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy"); java.util.Date parsedDate = dateFormat.parse(date); dateFormat = new SimpleDateFormat("yyyy-MM-dd"); date = dateFormat.format(parsedDate); System.out.println(date); java.sql.Date sqlDate = java.sql.Date.valueOf(date); System.out.println(sqlDate); } catch (ParseException e) { e.printStackTrace(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload