Use method prepareStatement of Class Connection to create statement instead
of  createStatement

  PreparedStatement pstmt = con.prepareStatement("INSERT INTO
LOG(logtime,event) values (?,?)");
> java.sql.Date sqlDate = new java.sql.Date(birthday.getTime());
   String  message = ....;

after you can pass sqlDate as parameter to the statement through method
setDate

   pstmt.setDate(1, sqlDate );
   pstmt.setString(2, message );

Now,
    pstmt.executeUpdate();

to insert this record to table



> java.sql.Date sqlDate = new java.sql.Date(birthday.getTime());
>
> and to pass it as parameter of the setDate(java.sql.Date) method
>
> ----- Original Message -----
> From: "Emmanuel Eze" <[EMAIL PROTECTED]>
> To: "JDJList" <[EMAIL PROTECTED]>
> Sent: Tuesday, May 07, 2002 11:03 AM
> Subject: [jdjlist] 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 interger 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 folllowing 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 chnage it to:
> > birthday = (java.sql.Date) cbirthday.getTime();
> >
> > Pls tell me what I'm doing wrongly.
> >
> > Emma
> >
> >
> > To change your membership options, refer to:
> > http://www.sys-con.com/java/list.cfm
> >
>
>
> To change your membership options, refer to:
> http://www.sys-con.com/java/list.cfm
>
>
>



To change your membership options, refer to:
http://www.sys-con.com/java/list.cfm

Reply via email to