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
Re: sql Date
First of all:- java.util.sql birthday = null; should be java.util.Date birthday = null; as the Calendar.getTime() method returns a util date object. -Original Message- From: Emmanuel Eze [mailto:[EMAIL PROTECTED]] Sent: Tuesday, May 07, 2002 1:34 PM 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
Re: sql Date
Even if I do that, how do I then convert the java.util.Date to java.sql.Date? -Original Message- From: Bhushan_Bhangale [mailto:[EMAIL PROTECTED]] Sent: Tuesday, May 07, 2002 11:05 AM To: [EMAIL PROTECTED] Subject: Re: sql Date First of all:- java.util.sql birthday = null; should be java.util.Date birthday = null; as the Calendar.getTime() method returns a util date object. -Original Message- From: Emmanuel Eze [mailto:[EMAIL PROTECTED]] Sent: Tuesday, May 07, 2002 1:34 PM 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 === 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
Re: sql Date
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
Re: sql Date
You cannot cast a java.util.Date to a java.sql.Date since the util.Date is the parent class of sql Date. -Original Message- From: Emmanuel Eze [mailto:[EMAIL PROTECTED]] Sent: Tuesday, May 07, 2002 1:46 PM To: [EMAIL PROTECTED] Subject: Re: sql Date Even if I do that, how do I then convert the java.util.Date to java.sql.Date? -Original Message- From: Bhushan_Bhangale [mailto:[EMAIL PROTECTED]] Sent: Tuesday, May 07, 2002 11:05 AM To: [EMAIL PROTECTED] Subject: Re: sql Date First of all:- java.util.sql birthday = null; should be java.util.Date birthday = null; as the Calendar.getTime() method returns a util date object. -Original Message- From: Emmanuel Eze [mailto:[EMAIL PROTECTED]] Sent: Tuesday, May 07, 2002 1:34 PM 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 === 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
Re: sql Date
hi, for inserting a date into the database, i use the following code. Calendar cal; // The date to be inserted String colValue = ""; colValue = "'"+(cal.get(Calendar.MONTH)+1)+"/"+cal.get(Calendar.DAY_OF_MONTH)+"/"+cal.g et(Calendar.YEAR) +" "+cal.get(Calendar.HOUR_OF_DAY) + ":"+cal.get(Calendar.MINUTE)+"'"; then.. String sql = "Insert into table(...) values ('aa'," + colValue + ")" then use sql for inserting the record. hth, Nagarajan. > -Original Message- > From: A mailing list about Java Server Pages specification and reference > [mailto:[EMAIL PROTECTED]]On Behalf Of Bhushan_Bhangale > Sent: Tuesday, May 07, 2002 11:14 AM > To: [EMAIL PROTECTED] > Subject: Re: sql Date > > > You cannot cast a java.util.Date to a java.sql.Date since the util.Date is > the parent class of sql Date. > > -Original Message- > From: Emmanuel Eze [mailto:[EMAIL PROTECTED]] > Sent: Tuesday, May 07, 2002 1:46 PM > To: [EMAIL PROTECTED] > Subject: Re: sql Date > > > Even if I do that, how do I then convert the java.util.Date to > java.sql.Date? > > > -Original Message- > From: Bhushan_Bhangale [mailto:[EMAIL PROTECTED]] > Sent: Tuesday, May 07, 2002 11:05 AM > To: [EMAIL PROTECTED] > Subject: Re: sql Date > > > First of all:- > > java.util.sql birthday = null; should be java.util.Date > birthday = null; > > as the Calendar.getTime() method returns a util date object. > > -Original Message- > From: Emmanuel Eze [mailto:[EMAIL PROTECTED]] > Sent: Tuesday, May 07, 2002 1:34 PM > 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 > > == > = > 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 === 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
Re: sql Date
just make that as explicit casting like what have you done is correct. use preparedstatement and then use setObject method. Regards Ramesh Kesavanarayanan [EMAIL PROTECTED] Off : 8113801 ext 2333 Res : 2265360 Mob : 98412 73573 > -Original Message- > From: Emmanuel Eze [SMTP:[EMAIL PROTECTED]] > Sent: Tuesday, May 07, 2002 1:46 PM > To: [EMAIL PROTECTED] > Subject: Re: sql Date > > Even if I do that, how do I then convert the java.util.Date to > java.sql.Date? > > > -Original Message- > From: Bhushan_Bhangale [mailto:[EMAIL PROTECTED]] > Sent: Tuesday, May 07, 2002 11:05 AM > To: [EMAIL PROTECTED] > Subject: Re: sql Date > > > First of all:- > > java.util.sql birthday = null; should be java.util.Date birthday = > null; > > as the Calendar.getTime() method returns a util date object. > > -Original Message- > From: Emmanuel Eze [mailto:[EMAIL PROTECTED]] > Sent: Tuesday, May 07, 2002 1:34 PM > 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 > > == > = > 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
Re: sql Date
make the following correction Calendar cbirthday = null; java.util.sql birthday = null; as java.sql.Date 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(); Regards Ramesh Kesavanarayanan [EMAIL PROTECTED] Off : 8113801 ext 2333 Res : 2265360 Mob : 98412 73573 === 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
Re: sql Date
Hi, That' pretty dangerous, what if the DB is expecting day then month (UK standard) instead of month then day (US Standard) ? From my experience that is a common issue with dates and DB's. It may be poossible to use SQL functions to build the date up. Cheers Adrian > -Original Message- > From: G.Nagarajan [SMTP:[EMAIL PROTECTED]] > Sent: 07 May 2002 11:29 > To: [EMAIL PROTECTED] > Subject: Re: sql Date > > hi, > > for inserting a date into the database, i use the following code. > > Calendar cal; // The date to be inserted > String colValue = ""; > colValue = > "'"+(cal.get(Calendar.MONTH)+1)+"/"+cal.get(Calendar.DAY_OF_MONTH)+"/"+cal > .g > et(Calendar.YEAR) > +" "+cal.get(Calendar.HOUR_OF_DAY) + > ":"+cal.get(Calendar.MINUTE)+"'"; > > then.. > > String sql = "Insert into table(...) values ('aa'," + colValue + ")" > > then use sql for inserting the record. > > > hth, > Nagarajan. > > > -Original Message- > > From: A mailing list about Java Server Pages specification and reference > > [mailto:[EMAIL PROTECTED]]On Behalf Of Bhushan_Bhangale > > Sent: Tuesday, May 07, 2002 11:14 AM > > To: [EMAIL PROTECTED] > > Subject: Re: sql Date > > > > > > You cannot cast a java.util.Date to a java.sql.Date since the util.Date > is > > the parent class of sql Date. > > > > -Original Message- > > From: Emmanuel Eze [mailto:[EMAIL PROTECTED]] > > Sent: Tuesday, May 07, 2002 1:46 PM > > To: [EMAIL PROTECTED] > > Subject: Re: sql Date > > > > > > Even if I do that, how do I then convert the java.util.Date to > > java.sql.Date? > > > > > > -Original Message- > > From: Bhushan_Bhangale [mailto:[EMAIL PROTECTED]] > > Sent: Tuesday, May 07, 2002 11:05 AM > > To: [EMAIL PROTECTED] > > Subject: Re: sql Date > > > > > > First of all:- > > > > java.util.sql birthday = null; should be java.util.Date > > birthday = null; > > > > as the Calendar.getTime() method returns a util date object. > > > > -Original Message- > > From: Emmanuel Eze [mailto:[EMAIL PROTECTED]] > > Sent: Tuesday, May 07, 2002 1:34 PM > > 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 > > > > == > > =
Re: sql Date
how do I acheive explicit casting because that is what the compiler complained about? I thought the following line should be ok but it rejects it. birthday = (java.sql.Date) cbirthday.getTime(); -Original Message- From: Kesav, Ramesh [mailto:[EMAIL PROTECTED]] Sent: Tuesday, May 07, 2002 11:17 AM To: [EMAIL PROTECTED] Subject: Re: sql Date just make that as explicit casting like what have you done is correct. use preparedstatement and then use setObject method. Regards Ramesh Kesavanarayanan [EMAIL PROTECTED] Off : 8113801 ext 2333 Res : 2265360 Mob : 98412 73573 > -Original Message- > From: Emmanuel Eze [SMTP:[EMAIL PROTECTED]] > Sent: Tuesday, May 07, 2002 1:46 PM > To: [EMAIL PROTECTED] > Subject: Re: sql Date > > Even if I do that, how do I then convert the java.util.Date to > java.sql.Date? > > > -Original Message- > From: Bhushan_Bhangale [mailto:[EMAIL PROTECTED]] > Sent: Tuesday, May 07, 2002 11:05 AM > To: [EMAIL PROTECTED] > Subject: Re: sql Date > > > First of all:- > > java.util.sql birthday = null; should be java.util.Date birthday = > null; > > as the Calendar.getTime() method returns a util date object. > > -Original Message- > From: Emmanuel Eze [mailto:[EMAIL PROTECTED]] > Sent: Tuesday, May 07, 2002 1:34 PM > 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 > > == > = > 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 === 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
Re: sql Date
I agree dates, databases and locales can be horrible, I tend to convert dates into strings of known format then explicitly cast them from Strings into datetimes using SQL. I then always know exactly what I'm doing all the time. Chris -Original Message- From: Adrian Janssen [mailto:[EMAIL PROTECTED]] Sent: Tuesday, May 07, 2002 10:39 AM To: [EMAIL PROTECTED] Subject: Re: sql Date Hi, That' pretty dangerous, what if the DB is expecting day then month (UK standard) instead of month then day (US Standard) ? From my experience that is a common issue with dates and DB's. It may be poossible to use SQL functions to build the date up. Cheers Adrian > -Original Message- > From: G.Nagarajan [SMTP:[EMAIL PROTECTED]] > Sent: 07 May 2002 11:29 > To: [EMAIL PROTECTED] > Subject: Re: sql Date > > hi, > > for inserting a date into the database, i use the following code. > > Calendar cal; // The date to be inserted > String colValue = ""; > colValue = > "'"+(cal.get(Calendar.MONTH)+1)+"/"+cal.get(Calendar.DAY_OF_MONTH)+"/"+cal > .g > et(Calendar.YEAR) > +" "+cal.get(Calendar.HOUR_OF_DAY) + > ":"+cal.get(Calendar.MINUTE)+"'"; > > then.. > > String sql = "Insert into table(...) values ('aa'," + colValue + ")" > > then use sql for inserting the record. > > > hth, > Nagarajan. > > > -Original Message- > > From: A mailing list about Java Server Pages specification and reference > > [mailto:[EMAIL PROTECTED]]On Behalf Of Bhushan_Bhangale > > Sent: Tuesday, May 07, 2002 11:14 AM > > To: [EMAIL PROTECTED] > > Subject: Re: sql Date > > > > > > You cannot cast a java.util.Date to a java.sql.Date since the util.Date > is > > the parent class of sql Date. > > > > -Original Message- > > From: Emmanuel Eze [mailto:[EMAIL PROTECTED]] > > Sent: Tuesday, May 07, 2002 1:46 PM > > To: [EMAIL PROTECTED] > > Subject: Re: sql Date > > > > > > Even if I do that, how do I then convert the java.util.Date to > > java.sql.Date? > > > > > > -Original Message- > > From: Bhushan_Bhangale [mailto:[EMAIL PROTECTED]] > > Sent: Tuesday, May 07, 2002 11:05 AM > > To: [EMAIL PROTECTED] > > Subject: Re: sql Date > > > > > > First of all:- > > > > java.util.sql birthday = null; should be java.util.Date > > birthday = null; > > > > as the Calendar.getTime() method returns a util date object. > > > > -Original Message- > > From: Emmanuel Eze [mailto:[EMAIL PROTECTED]] > > Sent: Tuesday, May 07, 2002 1:34 PM > > 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
Re: sql Date
That's baaad! You should use a PreparedStatement. Geert Van Damme > -Original Message- > From: A mailing list about Java Server Pages specification and reference > [mailto:[EMAIL PROTECTED]]On Behalf Of G.Nagarajan > Sent: dinsdag 7 mei 2002 11:29 > To: [EMAIL PROTECTED] > Subject: Re: sql Date > > > hi, > > for inserting a date into the database, i use the following code. > > Calendar cal; // The date to be inserted > String colValue = ""; > colValue = > "'"+(cal.get(Calendar.MONTH)+1)+"/"+cal.get(Calendar.DAY_OF_MONTH) > +"/"+cal.g > et(Calendar.YEAR) > +" > "+cal.get(Calendar.HOUR_OF_DAY) + ":"+cal.get(Calendar.MINUTE)+"'"; > > then.. > > String sql = "Insert into table(...) values ('aa'," + colValue + ")" > > then use sql for inserting the record. > > > hth, > Nagarajan. > > > -Original Message- > > From: A mailing list about Java Server Pages specification and reference > > [mailto:[EMAIL PROTECTED]]On Behalf Of Bhushan_Bhangale > > Sent: Tuesday, May 07, 2002 11:14 AM > > To: [EMAIL PROTECTED] > > Subject: Re: sql Date > > > > > > You cannot cast a java.util.Date to a java.sql.Date since the > util.Date is > > the parent class of sql Date. > > > > -Original Message- > > From: Emmanuel Eze [mailto:[EMAIL PROTECTED]] > > Sent: Tuesday, May 07, 2002 1:46 PM > > To: [EMAIL PROTECTED] > > Subject: Re: sql Date > > > > > > Even if I do that, how do I then convert the java.util.Date to > > java.sql.Date? > > > > > > -Original Message- > > From: Bhushan_Bhangale [mailto:[EMAIL PROTECTED]] > > Sent: Tuesday, May 07, 2002 11:05 AM > > To: [EMAIL PROTECTED] > > Subject: Re: sql Date > > > > > > First of all:- > > > > java.util.sql birthday = null; should be java.util.Date > > birthday = null; > > > > as the Calendar.getTime() method returns a util date object. > > > > -Original Message- > > From: Emmanuel Eze [mailto:[EMAIL PROTECTED]] > > Sent: Tuesday, May 07, 2002 1:34 PM > > 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 > > > > == > > = > > To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff > > JSP-INTEREST". > > For digest:
Re: sql Date
cbirthday.getTime() returns a long - which cannot be cast to any type of Date. Change your code to: birthday = new java.sql.Date ( cbirthday.getTime() ); > -Original Message- > From: Emmanuel Eze [SMTP:[EMAIL PROTECTED]] > Sent: 07 May 2002 10:50 > To: [EMAIL PROTECTED] > Subject: Re: sql Date > > how do I acheive explicit casting because that is what the compiler > complained about? > I thought the following line should be ok but it rejects it. > > birthday = (java.sql.Date) cbirthday.getTime(); > > > > -Original Message- > From: Kesav, Ramesh [mailto:[EMAIL PROTECTED]] > Sent: Tuesday, May 07, 2002 11:17 AM > To: [EMAIL PROTECTED] > Subject: Re: sql Date > > > just make that as explicit casting like what have you done is correct. > > use preparedstatement and then use setObject method. > > Regards > > Ramesh Kesavanarayanan > [EMAIL PROTECTED] > Off : 8113801 ext 2333 > Res : 2265360 > Mob : 98412 73573 > > > > -Original Message- > > From: Emmanuel Eze [SMTP:[EMAIL PROTECTED]] > > Sent: Tuesday, May 07, 2002 1:46 PM > > To: [EMAIL PROTECTED] > > Subject: Re: sql Date > > > > Even if I do that, how do I then convert the java.util.Date to > > java.sql.Date? > > > > > > -Original Message- > > From: Bhushan_Bhangale [mailto:[EMAIL PROTECTED]] > > Sent: Tuesday, May 07, 2002 11:05 AM > > To: [EMAIL PROTECTED] > > Subject: Re: sql Date > > > > > > First of all:- > > > > java.util.sql birthday = null; should be java.util.Date birthday = > > null; > > > > as the Calendar.getTime() method returns a util date object. > > > > -Original Message- > > From: Emmanuel Eze [mailto:[EMAIL PROTECTED]] > > Sent: Tuesday, May 07, 2002 1:34 PM > > 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 > > > > > == > > = > > 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 > > =
Re: sql Date
It returns java.util.Date and not long. By the Emmanuel Eze have you found the solution for your problem yet or not? -Original Message- From: Adrian Janssen [mailto:[EMAIL PROTECTED]] Sent: Tuesday, May 07, 2002 3:25 PM To: [EMAIL PROTECTED] Subject: Re: sql Date cbirthday.getTime() returns a long - which cannot be cast to any type of Date. Change your code to: birthday = new java.sql.Date ( cbirthday.getTime() ); > -Original Message- > From: Emmanuel Eze [SMTP:[EMAIL PROTECTED]] > Sent: 07 May 2002 10:50 > To: [EMAIL PROTECTED] > Subject: Re: sql Date > > how do I acheive explicit casting because that is what the compiler > complained about? > I thought the following line should be ok but it rejects it. > > birthday = (java.sql.Date) cbirthday.getTime(); > > > > -Original Message- > From: Kesav, Ramesh [mailto:[EMAIL PROTECTED]] > Sent: Tuesday, May 07, 2002 11:17 AM > To: [EMAIL PROTECTED] > Subject: Re: sql Date > > > just make that as explicit casting like what have you done is correct. > > use preparedstatement and then use setObject method. > > Regards > > Ramesh Kesavanarayanan > [EMAIL PROTECTED] > Off : 8113801 ext 2333 > Res : 2265360 > Mob : 98412 73573 > > > > -Original Message- > > From: Emmanuel Eze [SMTP:[EMAIL PROTECTED]] > > Sent: Tuesday, May 07, 2002 1:46 PM > > To: [EMAIL PROTECTED] > > Subject: Re: sql Date > > > > Even if I do that, how do I then convert the java.util.Date to > > java.sql.Date? > > > > > > -Original Message- > > From: Bhushan_Bhangale [mailto:[EMAIL PROTECTED]] > > Sent: Tuesday, May 07, 2002 11:05 AM > > To: [EMAIL PROTECTED] > > Subject: Re: sql Date > > > > > > First of all:- > > > > java.util.sql birthday = null; should be java.util.Date birthday = > > null; > > > > as the Calendar.getTime() method returns a util date object. > > > > -Original Message- > > From: Emmanuel Eze [mailto:[EMAIL PROTECTED]] > > Sent: Tuesday, May 07, 2002 1:34 PM > > 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 > > > > > == > > = > > 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/S
Re: sql Date
Yes I have. -Original Message- From: Bhushan_Bhangale [mailto:[EMAIL PROTECTED]] Sent: Tuesday, May 07, 2002 12:12 PM To: [EMAIL PROTECTED] Subject: Re: sql Date It returns java.util.Date and not long. By the Emmanuel Eze have you found the solution for your problem yet or not? -Original Message- From: Adrian Janssen [mailto:[EMAIL PROTECTED]] Sent: Tuesday, May 07, 2002 3:25 PM To: [EMAIL PROTECTED] Subject: Re: sql Date cbirthday.getTime() returns a long - which cannot be cast to any type of Date. Change your code to: birthday = new java.sql.Date ( cbirthday.getTime() ); > -Original Message- > From: Emmanuel Eze [SMTP:[EMAIL PROTECTED]] > Sent: 07 May 2002 10:50 > To: [EMAIL PROTECTED] > Subject: Re: sql Date > > how do I acheive explicit casting because that is what the compiler > complained about? > I thought the following line should be ok but it rejects it. > > birthday = (java.sql.Date) cbirthday.getTime(); > > > > -Original Message- > From: Kesav, Ramesh [mailto:[EMAIL PROTECTED]] > Sent: Tuesday, May 07, 2002 11:17 AM > To: [EMAIL PROTECTED] > Subject: Re: sql Date > > > just make that as explicit casting like what have you done is correct. > > use preparedstatement and then use setObject method. > > Regards > > Ramesh Kesavanarayanan > [EMAIL PROTECTED] > Off : 8113801 ext 2333 > Res : 2265360 > Mob : 98412 73573 > > > > -Original Message- > > From: Emmanuel Eze [SMTP:[EMAIL PROTECTED]] > > Sent: Tuesday, May 07, 2002 1:46 PM > > To: [EMAIL PROTECTED] > > Subject: Re: sql Date > > > > Even if I do that, how do I then convert the java.util.Date to > > java.sql.Date? > > > > > > -Original Message- > > From: Bhushan_Bhangale [mailto:[EMAIL PROTECTED]] > > Sent: Tuesday, May 07, 2002 11:05 AM > > To: [EMAIL PROTECTED] > > Subject: Re: sql Date > > > > > > First of all:- > > > > java.util.sql birthday = null; should be java.util.Date birthday = > > null; > > > > as the Calendar.getTime() method returns a util date object. > > > > -Original Message- > > From: Emmanuel Eze [mailto:[EMAIL PROTECTED]] > > Sent: Tuesday, May 07, 2002 1:34 PM > > 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 > > > > > == > > = > > To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff > > JSP-INTEREST". > &g
Re: sql Date
NO!. cbirthday.getTime() returns a java.util.Date. Remember that cbirthday is a Calendar object. -Original Message- From: Adrian Janssen [mailto:[EMAIL PROTECTED]] Sent: Tuesday, May 07, 2002 11:55 AM To: [EMAIL PROTECTED] Subject: Re: sql Date cbirthday.getTime() returns a long - which cannot be cast to any type of Date. Change your code to: birthday = new java.sql.Date ( cbirthday.getTime() ); > -Original Message- > From: Emmanuel Eze [SMTP:[EMAIL PROTECTED]] > Sent: 07 May 2002 10:50 > To: [EMAIL PROTECTED] > Subject: Re: sql Date > > how do I acheive explicit casting because that is what the compiler > complained about? > I thought the following line should be ok but it rejects it. > > birthday = (java.sql.Date) cbirthday.getTime(); > > > > -Original Message- > From: Kesav, Ramesh [mailto:[EMAIL PROTECTED]] > Sent: Tuesday, May 07, 2002 11:17 AM > To: [EMAIL PROTECTED] > Subject: Re: sql Date > > > just make that as explicit casting like what have you done is correct. > > use preparedstatement and then use setObject method. > > Regards > > Ramesh Kesavanarayanan > [EMAIL PROTECTED] > Off : 8113801 ext 2333 > Res : 2265360 > Mob : 98412 73573 > > > > -Original Message- > > From: Emmanuel Eze [SMTP:[EMAIL PROTECTED]] > > Sent: Tuesday, May 07, 2002 1:46 PM > > To: [EMAIL PROTECTED] > > Subject: Re: sql Date > > > > Even if I do that, how do I then convert the java.util.Date to > > java.sql.Date? > > > > > > -Original Message- > > From: Bhushan_Bhangale [mailto:[EMAIL PROTECTED]] > > Sent: Tuesday, May 07, 2002 11:05 AM > > To: [EMAIL PROTECTED] > > Subject: Re: sql Date > > > > > > First of all:- > > > > java.util.sql birthday = null; should be java.util.Date birthday = > > null; > > > > as the Calendar.getTime() method returns a util date object. > > > > -Original Message- > > From: Emmanuel Eze [mailto:[EMAIL PROTECTED]] > > Sent: Tuesday, May 07, 2002 1:34 PM > > 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 > > > > > == > > = > > 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/S
Re: sql Date
oops! Was reading javadocs for java.util.Date.getTime() instead of Calender.getTime(). > -Original Message- > From: Bhushan_Bhangale [SMTP:[EMAIL PROTECTED]] > Sent: 07 May 2002 12:12 > To: [EMAIL PROTECTED] > Subject: Re: sql Date > > It returns java.util.Date and not long. > > By the Emmanuel Eze have you found the solution for your problem yet or > not? > > -Original Message- > From: Adrian Janssen [mailto:[EMAIL PROTECTED]] > Sent: Tuesday, May 07, 2002 3:25 PM > To: [EMAIL PROTECTED] > Subject: Re: sql Date > > > cbirthday.getTime() returns a long - which cannot be cast to any type of > Date. Change your code to: > > birthday = new java.sql.Date ( cbirthday.getTime() ); > > > > -Original Message- > > From: Emmanuel Eze [SMTP:[EMAIL PROTECTED]] > > Sent: 07 May 2002 10:50 > > To: [EMAIL PROTECTED] > > Subject: Re: sql Date > > > > how do I acheive explicit casting because that is what the compiler > > complained about? > > I thought the following line should be ok but it rejects it. > > > > birthday = (java.sql.Date) cbirthday.getTime(); > > > > > > > > -----Original Message- > > From: Kesav, Ramesh [mailto:[EMAIL PROTECTED]] > > Sent: Tuesday, May 07, 2002 11:17 AM > > To: [EMAIL PROTECTED] > > Subject: Re: sql Date > > > > > > just make that as explicit casting like what have you done is correct. > > > > use preparedstatement and then use setObject method. > > > > Regards > > > > Ramesh Kesavanarayanan > > [EMAIL PROTECTED] > > Off : 8113801 ext 2333 > > Res : 2265360 > > Mob : 98412 73573 > > > > > > > -Original Message- > > > From: Emmanuel Eze [SMTP:[EMAIL PROTECTED]] > > > Sent: Tuesday, May 07, 2002 1:46 PM > > > To: [EMAIL PROTECTED] > > > Subject: Re: sql Date > > > > > > Even if I do that, how do I then convert the java.util.Date to > > > java.sql.Date? > > > > > > > > > -Original Message- > > > From: Bhushan_Bhangale [mailto:[EMAIL PROTECTED]] > > > Sent: Tuesday, May 07, 2002 11:05 AM > > > To: [EMAIL PROTECTED] > > > Subject: Re: sql Date > > > > > > > > > First of all:- > > > > > > java.util.sql birthday = null; should be java.util.Date birthday = > > > null; > > > > > > as the Calendar.getTime() method returns a util date object. > > > > > > -Original Message- > > > From: Emmanuel Eze [mailto:[EMAIL PROTECTED]] > > > Sent: Tuesday, May 07, 2002 1:34 PM > > > 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 > > > > > > > > > =
Re: SQL Date Arithemtic
I am selecting smalldatetime field from a table in my db. I would like to know how to compare the date values in the query to certain criteria (eg 48 hours ago, 10 days from now, etc...) that I specify in my JSP code and then display. Please help __ Do You Yahoo!? Yahoo! Photos - 35mm Quality Prints, Now Get 15 Free! http://photos.yahoo.com/ === To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST". Some relevant FAQs on JSP/Servlets can be found at: http://java.sun.com/products/jsp/faq.html http://www.esperanto.org.nz/jsp/jspfaq.html http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
Re: SQL Date Arithemtic
1. First you have to create a proper util.Date object by parsing the date string selected in the table. You can use standard parsers. Refer to java.text. 2. You then have to get the java.util.Calendar object for the Date so created. This class has many util methods to compare, add to, subtract from the your Date. You can also set individual attributes like day of the week, day of the month, month of the year etc. Hope this helps .. - Ajit Dan Lopez wrote: > > I am selecting smalldatetime field from a table in my > db. I would like to know how to compare the date > values in the query to certain criteria (eg 48 hours > ago, 10 days from now, etc...) that I specify in my > JSP code and then display. Please help > > __ > Do You Yahoo!? > Yahoo! Photos - 35mm Quality Prints, Now Get 15 Free! > http://photos.yahoo.com/ > > === > To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST". > Some relevant FAQs on JSP/Servlets can be found at: > > http://java.sun.com/products/jsp/faq.html > http://www.esperanto.org.nz/jsp/jspfaq.html > http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP > http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets === To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST". Some relevant FAQs on JSP/Servlets can be found at: http://java.sun.com/products/jsp/faq.html http://www.esperanto.org.nz/jsp/jspfaq.html http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
Re: SQL Date Arithemtic
Right now I do something like this for an example: <%@ page import="java.util.*, java.text.SimpleDateFormat"%> <% SimpleDateFormat datef, timef; Date tim = new Date(); Locale fi = new Locale( "fi", "FI" ); datef = new SimpleDateFormat( "MM.dd.", fi ); timef = new SimpleDateFormat( "HH:mm:ss", fi); int hours; hours = tim.getHours(); int days; days = tim.getDay(); %> The current date at the server is <%= tim %>. Display date only: <%= datef.format(tim) %> Display numeric value of the day of the week only (i.e. Thursday = 4): <%= days %> Display comparison of numeric conversion days of the week: <% if (days > 1) { %> Text is orange but could be row color <% } %> <% if (days == 3) { %> Text is blue but could be row color, etc <% } %> <% if (days < 5) { %> Text is red but could be row color <% } %> Display time only: <%= timef.format(tim) %> And so forth...All works fine. But I cant seem to be able to compare values of that date and the date from the database. So how should I change my page objective (ie java.util*) to be able to do date arithmetic? My SQL query gets a value like "Oct 1 2000 12:00AM" as a smalldatetime. I think the way I did it in JSP looks like "TUES OCT 2 2000 GMT 1200AM." Suggestions? --- Ajit Bhingarkar <[EMAIL PROTECTED]> wrote: > 1. First you have to create a proper util.Date > object > by parsing the date string selected in the table. > You can use standard parsers. Refer to java.text. > 2. You then have to get the java.util.Calendar > object for the > Date so created. This class has many util methods to > compare, add to, subtract from the your Date. > You can also set individual attributes like day of > the week, > day of the month, month of the year etc. > > Hope this helps .. > > - Ajit > > Dan Lopez wrote: > > > > I am selecting smalldatetime field from a table in > my > > db. I would like to know how to compare the date > > values in the query to certain criteria (eg 48 > hours > > ago, 10 days from now, etc...) that I specify in > my > > JSP code and then display. Please help > > > > __ > > Do You Yahoo!? > > Yahoo! Photos - 35mm Quality Prints, Now Get 15 > Free! > > http://photos.yahoo.com/ > > > > > === > > To unsubscribe: mailto [EMAIL PROTECTED] with > body: "signoff JSP-INTEREST". > > Some relevant FAQs on JSP/Servlets can be found > at: > > > > http://java.sun.com/products/jsp/faq.html > > http://www.esperanto.org.nz/jsp/jspfaq.html > > > http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP > > > http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets > > === > To unsubscribe: mailto [EMAIL PROTECTED] with > body: "signoff JSP-INTEREST". > Some relevant FAQs on JSP/Servlets can be found at: > > http://java.sun.com/products/jsp/faq.html > http://www.esperanto.org.nz/jsp/jspfaq.html > http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP > http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets __ Do You Yahoo!? Yahoo! Photos - 35mm Quality Prints, Now Get 15 Free! http://photos.yahoo.com/ === To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST". Some relevant FAQs on JSP/Servlets can be found at: http://java.sun.com/products/jsp/faq.html http://www.esperanto.org.nz/jsp/jspfaq.html http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
Answer to Oracle/SQL date and Java Date question
I am sorry, I lost the original question e-mail. You need to do something like java.sql.Date d1 = new java.sql.Date(myDate.getTime()); prepStmt.setDate(2, d1); where myDate is java.util.Date and prepStmt is a PreparedStatement. You can also try oracle.sql.Date. Of course you can also do rset.getDate(1) where rset is your ResultSet. Benjamin === 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://java.sun.com/products/jsp/faq.html http://www.esperanto.org.nz/jsp/jspfaq.html http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets