title: Inserting date in a database using PreparedStatement in Java
body: <p>I have a form which captures a date that the user input in a JFormattedTextField. Then the Date need to be stored in a database (postgresql) using PreparedStatement. I am having error messages at the line pStat.setDate(4, dob);.</p>
  
  <pre><code> Date dob = (Date)ftxtDOB.getValue();
         String add = txtAddress.getText();
         String country = txtCountry.getText();
         try {
             Class.forName("org.postgresql.Driver");
             conn = DriverManager.getConnection("jdbc:postgresql://127.0.0.1:5432/postgres", "postgres","cisco");
  
             pStat = conn.prepareStatement("INSERT INTO customer_info VALUES (?,?,?,?,?,?)");
             pStat.setString(1, id);
             pStat.setString(2, surname);
             pStat.setString(3, fName);
             pStat.setDate(4, dob);
         }catch(Exception e){
  
         }
  </code></pre>
  
  <p>Edit: I have this error message from the compiler.</p>
  
  <pre><code>no suitable method found for setDate(int,java.util.Date)
      method java.sql.PreparedStatement.setDate(int,java.sql.Date,java.util.Calendar) is not applicable
        (actual and formal argument lists differ in length)
      method java.sql.PreparedStatement.setDate(int,java.sql.Date) is not applicable
        (actual argument java.util.Date cannot be converted to java.sql.Date by method invocation conversion)
  </code></pre>
  
  <p>Edit: SOLVED, I used:</p>
  
  <pre><code>    pStat.setDate(4, new java.sql.Date(dob.getTime()));
  </code></pre>