You cannot cast a java.util.Date to a java.sql.Date since the util.Date is in fact the ancestor class. The fact that there are so many different date types. java.util.Date, java.sql.Date, java.sql.Timestamp, Calendar,...
It's a real mess. Worst of all is that it's not always obvious to convert one into the other. big tip: Most of them provide a getTime() function which returns the millisecond time. and this can often be used to create another type. In your case, you get a java.util.Date and you need a java.sql.Date. java.sql.Date birthday = new java.sql.Date( cbirthday.getTime()); Geert Van Damme > -----Original Message----- > From: A mailing list about Java Server Pages specification and reference > [mailto:[EMAIL PROTECTED]]On Behalf Of Emmanuel Eze > Sent: dinsdag 7 mei 2002 10:04 > To: [EMAIL PROTECTED] > Subject: sql Date > > > Hi all, > > Can somebody pls tell me how I can insert a Date type into a > database table > with a Date datatype? > > I have the year, month, and day as integer values. I need to > convert these > values into an sql Date object so I can now insert the Date > object into the > table, right? > > I have the following code: > Calendar cbirthday = null; > java.util.sql birthday = null; > . > . > . > cbirthday = Calendar.getInstance(); > cbirthday.set(Integer.parseInt(year), Integer.parseInt(month), > Integer.parseInt(day)); > birthday = cbirthday.getTime(); > > This last statement throws a cast exception! Even when I change it to: > birthday = (java.sql.Date) cbirthday.getTime(); > > Pls tell me what I'm doing wrongly. > > Emma > > ================================================================== > ========= > To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff > JSP-INTEREST". > For digest: mailto [EMAIL PROTECTED] with body: "set > JSP-INTEREST DIGEST". > Some relevant FAQs on JSP/Servlets can be found at: > > http://archives.java.sun.com/jsp-interest.html > http://java.sun.com/products/jsp/faq.html > http://www.esperanto.org.nz/jsp/jspfaq.jsp > http://www.jguru.com/faq/index.jsp > http://www.jspinsider.com > =========================================================================== To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST". For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST". Some relevant FAQs on JSP/Servlets can be found at: http://archives.java.sun.com/jsp-interest.html http://java.sun.com/products/jsp/faq.html http://www.esperanto.org.nz/jsp/jspfaq.jsp http://www.jguru.com/faq/index.jsp http://www.jspinsider.com
