1 Reply Latest reply on Jan 19, 2003 5:32 PM by 3004

    Help selecting date

    843854
      I'm trying to search peoples in database based in the registred date
      but I'm getting lots of errors in date field, I'm using MS Access 2000
      my date field in Access is configured date/hour and i give the format dd/mm/yyyy if i try to insert a new name and date it work perfect, I'm inserting the date just getting the date typed in a JTextField and send it to database as a String without problem, down is the code I'm using to search by date
      //It search from a start date to a end date
      //I'm typing date like it  01/01/2003 to 20/01/2003
      
      if ( ! textField.fDat.getText().equals("") && ! textField.fTil.getText().equals("")  )
        {
          SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
          java.sql.Date sqlDate = java.sql.Date.valueOf(sdf.format( textField.fDat.getText()  ));
          java.sql.Date sqlDate2 = java.sql.Date.valueOf(sdf.format( textField.fTil.getText()  ));
                      
           query += " AND data >= '" + 
           sqlDate  + 
           "' AND data <= '" + 
           sqlDate2  + "'";
        }
      and I get that error

      java.lang.IllegalArgumentException: Cannot format given Object as a Date
      at java.text.DateFormat.format(DateFormat.java:279)
      at java.text.Format.format(Format.java:133)
        • 1. Re: Help selecting date
          3004
          this is really a Swing problem and not a JDBC problem but at any rate before your try and format the dates. print out the text you trying to format. i think it is null or some other unpleasantness and generally speaking not what you are expecting it to be.