2 Replies Latest reply on Dec 12, 2012 9:06 AM by gimbal2

    date comparison

      what is wrong with this code ?? i want to campare two date field but it shows error .
                String chkdt = request.getParameter("chkdt");
                SimpleDateFormat formater = new SimpleDateFormat("dd-MM-yyyy");
                 java.util.Date dt = formater.parse(chkdt);
                 java.sql.Date dte = new java.sql.Date(dt.getTime());
                 rst=stmt.executeQuery("select pf_party_name a, pf_cheque_amt b from pf_cheque_amt where pf_cheque_dt = " + dte );
      pf_cheque_dt is a column of a table of oracle data base and Data type of pf_cheque_dt is DATE,
      help me here..
      the error is
        ORA-00932: inconsistent datatypes: expected DATE got NUMBER 
        • 1. Re: date comparison
          You'll need to surround the value with apostrophes.

          But an even better way would be to learn to use PreparedStatements, which is the correct way and avoids that sort of problems (among others).
          1 person found this helpful
          • 2. Re: date comparison
            Kayaman wrote:
            You'll need to surround the value with apostrophes.
            Even that will probably not work as the query will now get the toString representation of the date object.

            I'm not even going to mention how to correct that, PreparedStatement is indeed the only true answer here.