title: Using setDate in PreparedStatement
body: <p>In order to make our code more standard, we were asked to change all the places where we hardcoded our SQL variables to prepared statements and bind the variables instead.</p>
  <p>I am however facing a problem with the <code>setDate()</code>.</p>
  <p>Here is the code:</p>
  <pre><code>DateFormat dateFormatYMD = new SimpleDateFormat(&quot;yyyy/MM/dd HH:mm:ss&quot;);
  DateFormat dateFormatMDY = new SimpleDateFormat(&quot;MM/dd/yyyy HH:mm:ss&quot;);
  Date now = new Date();
  String vDateYMD = dateFormatYMD.format(now);
  String vDateMDY = dateFormatMDY.format(now);
  String vDateMDYSQL =  vDateMDY ;
  java.sql.Date date = new java.sql.Date(0000-00-00);
  
  requestSQL = &quot;INSERT INTO CREDIT_REQ_TITLE_ORDER (REQUEST_ID,&quot; + 
               &quot; ORDER_DT, FOLLOWUP_DT) &quot; +  &quot;values(?,?,?,)&quot;;
  
  prs = conn.prepareStatement(requestSQL);
  prs.setInt(1,new Integer(requestID));
  prs.setDate(2,date.valueOf(vDateMDYSQL));
  prs.setDate(3,date.valueOf(sqlFollowupDT));
  </code></pre>
  <p>I get this error when the SQL gets executed:</p>
  <pre><code>java.lang.IllegalArgumentException
      at java.sql.Date.valueOf(Date.java:138)
      at com.cmsi.eValuate.TAF.TAFModuleMain.CallTAF(TAFModuleMain.java:1211)
  </code></pre>
  <p>Should I use <code>setString()</code> instead with a <code>to_date()</code>?</p>