Search code examples
javasqlderbyswingx

Error while storing jXDatePicker1 Date value in database


I am using swingxLabs' component jXDatePicker1 to pick date in a graphical format and trying to store it in the database made in derby. My code was this:

Date date=jXDatePicker1.getDate();

 PreparedStatement statement = connect
      .prepareStatement("INSERT INTO BILLING (DATE, DHRNUMBER) VALUES('"+date+"', "+dhrNumber+")");

The error which i am getting is:

java.sql.SQLDataException: The syntax of the string representation of a datetime value is incorrect.

Am i doing it right? Or there can be some other way to solve this.

Thanks


Solution

  • This alternative totally worked for me:

        Date d=jXDatePicker1.getDate();
        System.out.println(d);
        DateFormat df=new SimpleDateFormat("MM/dd/yyyy");
        String date=df.format(d);
        System.out.println(date);
    
    PreparedStatement statement = connect
          .prepareStatement("INSERT INTO BILLING (DATE) VALUES('"+date+"')");