I have the following code snippet where i get continous error for casting java.util.date to java.sql.date.
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
storedProcedureCall.setLong(1, 12345);
storedProcedureCall.setDate(2, (java.sql.Date) sdf.parse("09/02/2017"));
storedProcedureCall.setDate(3, (java.sql.Date) sdf.parse("10/02/2017"));
What am i doing wrong here. I have imported the java.util.Date package as well.
java.util.Dateandjava.sql.Date? I recommend the modern Java date and time API known as JSR-310 orjava.time. You can pass aLocalDateor other modern object toPreparedStatement.setObject(), also when using theCallableStatementsubinterface, of course.java.sql.Dateextends (is a subclass of)java.util.Date. Theparse()method returns ajava.util.Date, and you can't cast it to a subclass: stackoverflow.com/questions/30414859/…