How to convert String date to java sql date

I have an html form for entering the Date on retreving that value in a java servlet i get it as a string i want to convert that date to SQL date format so that i could use setDate() method of the java.sql.Date class to update the date value in the database.
i used the following way but i need the code without using the deprecated ones.
String delDate = (String)p_Request.getParameter("deleteDate");
[b]java.util.Date utilDate = new java.util.Date(delDate);
java.sql.Date deleteDate = new java.sql.Date(utilDate.getTime());
custCode = (String)p_Request.getValue("custCode");
thanx in advance.

Check out the later posts in http://forum.java.sun.com/thread.jspa?threadID=647681&messageID=3814745#3814745

Similar Messages

  • How to convert string yyyy-mm-dd to date dd/mm/yyyy

    Hi Experts,
    I am getting date in the form of string 2007-06-30 from R/3. How I can convert this string into a date in the form 30/06/2007. I have to use java.sql.Date.
    Following code is not working. As for executing the following code, I have to use java.util.date. I can not use java.util.date as the Web Dynpro program uses java.sql.Date.
         SimpleDateFormat sdf1 = new SimpleDateFormat("dd/mm/yyyy");
         Date d = null;
         d = sdf1.parse(wdContext.currentContextElement().getDateClicked());
    Regards,
    Gary

    Hi,
    If I understood you right you need this date typed as a java.sql.Date?
    String ds=wdContext.currentContextElement().getDateClicked();
    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");     
    java.sql.Date sd = new java.sql.Date(sdf.parse(ds).getTime());
    Four remarks:
    We "transport" the Date from java.util.Date to java.sql.Date as milliseconds since January 1, 1970, 00:00:00 GMT. See contract of java.sql.Date.
    You used dd/mm/yyyy instead of dd/MM/yyyy, but mm are the minutes and not the months, see the contract of [SimpleDateFormat|http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html] (JSE 1.4) .
    You do not set the time zone for DateFormat, so you use TimeZone.getDefault(). This is your JVM's default time zone and depends (if you did not change it) on your systems time zone. F.e. I live in Germany, the time zone of my system is currently MEZ (which is UTC+1) since we left the daylight saving time zone last sunday. Since you only parse the date and not the time zone f.e., you expect the date (the string) to be in your default time zone. If this is not the case, you have to set the time zone to the time zone you expect the date to be in (f.e. sdf1.setTimeZone(TimeZone.getTimeZone("UTC"));) before parsing the date. This might seem marginal in your case, but may produce unexpected results with date comparisons and date parsings around the day change.
    SimpleDateFormat is not thread-safe, so please do not cache it! This is not mentioned in the Javadoc of JSE 1.4, but can be looked up at [Sun's bug database|http://bugs.sun.com/bugdatabase/view_bug.do;jsessionid=96669461418011fffffffffb70dd6b6e88eb5?bug_id=4264153]. If you are not satisfied with the standard Date & Time handling (f.e. performance reasons) you might want to consider an alternative like [Joda Time|http://joda-time.sourceforge.net/index.html] which is published under [ASF 2.0 license|http://joda-time.sourceforge.net/license.html]
    Best regards,
    Fabian

  • How to change a date value from "java.util.Date" to "java.sql.Date"?

    Hi all,
    How to change a date value from "java.util.Date" to "java.sql.Date"?
    I m still confusing what's the difference between them.....
    thanks
    Regards,
    Kin

    Thanks
    but my sql statement can only accept the format (yyyy-MM-dd)
    such as "select * from xx where somedate = '2004-12-31'
    but when i show it to screen, i want to show it as dd-MM-yyyy
    I m using the following to change the jave.util.Date to str and vice versa. But it cannot shows the dd-MM-yyyy. I tried to change the format from yyyy-MM-dd to dd-MM-yyyy, it shows the wrong date in my application.
         public String date2str(java.util.Date thisdate)     {
              if (thisdate != null)     {
                   java.sql.Date thissDate = new java.sql.Date(thisdate.getTime());
                   return date2str(thissDate);
              }     else     {
                   return "";
         public String date2str(java.sql.Date thisdate)     {
              if (thisdate != null)     {
                   SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                   return sdf.format(thisdate);
              }     else     {
                   return "";
         public java.util.Date str2date(String thisdate)     {
              String dateFormat = "yyyy-MM-dd"; // = 1998-12-31
              java.util.Date returndate = null;
              if (thisdate != null)     {
                   SimpleDateFormat dateFormatter = new SimpleDateFormat(dateFormat);
                   try {
                        returndate = dateFormatter.parse(thisdate);
                   } catch (ParseException pe) {
                        System.out.println (pe.getMessage());
              return returndate;
         }

  • How do I create a Dynamic java.sql.Date ArrayList or Collection?

    I Have a MySQL table with a Datetime field with many values inserted.
    I want to know which is the Best way to capture all the Inserted DB values inside a Dynamic Array.
    I get errors that state that I should use Matching data-types, and plus I don't know how to create or fill a Dynamic Date ArrayList/Collection.
    Please Help, I need this urgently...

    package pruebadedates;
    import java.sql.*;
    * @author J?s?
    public class ClaseDeDates {
        /** Creates a new instance of ClaseDeDates */
         * @param args the command line arguments
        public static void main(String[] args) {
            java.sql.Date aDate[] = null;       
            Connection con = null;
            Statement stmt = null;
            ResultSet rs = null;
            try{
                Class.forName("com.mysql.jdbc.Driver").newInstance();
                con = DriverManager.getConnection("jdbc:mysql://localhost/pruebafechas", "root", "picardias");
                    if(!con.isClosed()){
                    stmt = con.createStatement();
                    stmt.executeQuery ("SELECT dates FROM datestable");
                    rs = stmt.getResultSet();
                        while (rs.next())
                        aDate[] = rs.getDate("dates");
            catch(Exception e)
               System.out.println(e);
            //System.out.println(aDate);     
    }Hi, There is my code and the errors that I get are:
    found : java.sql.Date
    required: java.sql.Date[]
    aDate = rs.getDate("dates");
    Actually I have No idea as How to get a Result set into an ArrayList or Collection. Please tell me how to do this Dynamically. I have like 25 records in that Database table, but they will grow, so I would really appreciate to know the code to do this. I suspect my problem is in the bolded part of my code.
    Thank you very much Sir.

  • Cannot convert from java.util.Date to java.sql.Date

    In the below code am trying to get the current date and 60 days prior date:
    Date  todayDate;
              Date  Sixtydaysprior;
              String DATE_FORMAT = "MM/dd/yy";
              DateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
             Calendar cal = Calendar.getInstance();
              todayDate = sdf.parse(sdf.format(cal.getTime()));
              cal.add(Calendar.DATE, -60);
             Sixtydaysprior = sdf.parse(sdf.format(cal.getTime()));I have imported following files:
    <%@page
         import="java.util.Calendar,
                   java.text.SimpleDateFormat,
                   java.text.ParseException,
                            java.util.*"
    %>Shows up following error msg:
    Type mismatch: cannot convert from java.util.Date to java.sql.Date
    Thanks.
    Edited by: MiltonDetroja on May 22, 2009 11:03 AM

    Shows up following error msg:
    Type mismatch: cannot convert from java.util.Date to java.sql.Date
    I don't think this exception is thrown from the portion of code you have shown. As clearly specified in exception message, you cannot cast an instance of java.util.Date to java.sql.Date. you will need to do something like this
    java.util.Date today = new java.util.Date();
    long t = today.getTime();
    java.sql.Date dt = new java.sql.Date(t);

  • (Again) java.util.Date vs java.sql.Date

    Hi there,
    (Again) Im trying to understand the EXACT difference between
    java.util.Date vs java.sql.Date.
    Googling, I can see that this is a very "popular" subject, but I still
    cannot figure out it exactly.
    Many writers claim that java.sql.Date only stores the DATE part (yyyy-
    mm-dd) but not the TIME part (hh:MM:ss) of a Date/Time value, but that
    I can easily disprove:
                    java.util.Date ud = new java.util.Date();                 java.sql.Date sd = new java.sql.Date(ud.getTime());                 System.out.println(DateFormatUtils.                                 format(ud, "yyyy-MM-dd HH:mm:ss.SSS"));                 System.out.println(DateFormatUtils.                                 format(sd, "yyyy-MM-dd HH:mm:ss.SSS"));
    Output:
                    2009-09-18 15:17:36.635                 2009-09-18 15:17:36.635
    So, apparently, java.sql.Date and java.util.Date have THE SAME
    precision (at least down to the millisecs...).
    And the official API documentation, really looks more confusing than
    helpful to me::
    *"java.sql.Date:*
    *A thin wrapper around a millisecond value that allows JDBC to identify*
    *this as an SQL DATE value. A milliseconds value represents the*
    *number of milliseconds that have passed since January 1, 1970*
    *00:00:00.000 GMT.*
    *To conform with the definition of SQL DATE, the millisecond values*
    *wrapped by a java.sql.Date instance must be 'normalized' by setting*
    *the hours, minutes, seconds, and milliseconds to zero in the*
    *particular time zone with which the instance is associated. "*
    Exactly what means "an SQL DATE value" ? How EXACTLY does it differ
    from a java.util.Date value?
    Most importantly: WHY does JDBC need to distinguish between them?
    And, here again: *"a java.sql.Date instance must be 'normalized' by*
    *setting the hours, minutes, seconds, and milliseconds to zero in the*
    *particular time zone..."*
    What does that mean exactly? Apparently, the constructor doesnt
    enforce this restriction, per the example above. So what's the REAL
    point with this type, java.sql.Date?
    Very greatful, if you can help me clarify this, once and for all.
    TIA,

    And the official API documentation, really looks more confusing than helpful to me:The problem is that you need to understand SQL as well as Java for this to make sense. It's not the Java API's job to tell you how your SQL database works - there's a myriad of subtle differences even when the DB is compliant with the SQL spec.
    Most compliant databases support DATE, TIME, and TIMESTAMP values. DATE represents only a date. TIME represents only a time. TIMESTAMP represents both. There are further complicating factors, but that's roughly how it stands.
    In Java the normal type for representing time is (or was when the API was created) the java.util.Date but this is a close approximation only to the TIMESTAMP value. In order to bring the two together the java.sql.Date, java.sql.Time and java.sql.Timestamp classes were created. Making them derive from java.util.Date was probably not a good idea.
    java.util.Date suffers from a number of deficiencies. java.util.Calendar was supposed to address them but didn't really succeed. The JodaTime library is rather better, but it's all a lot more complicated than you might expect - partly because time management really is a much harder problem than it appears at first glance - there are timezones, leap years, leap seconds, the difference between astronomical and atomic time, and so on and so forth.

  • Java.util.Date and java.sql.Date

    when i am trying to displaying date in my jsp page errors occurs saying that java.util.date and java.sql.date are matching..
    i have some sql statements which i need to execute in the page.so i cant delete that import sql statement.
    so what is the solution for this.
    i want to display the date as 19th april 2003....in the jsp page.
    thank u

    You should use full names.
    java.util.Date date;
    java.sql.Date sdate;
    ..And it may be a good idea to delete one of the two "import" declaration of packages.

  • Converting String to Date (java.sql.date)

    Hi,
    Kindly let me know how I can convert a string like
    "20061102" (YYYYMMDD) to a Date type (java.sql.date) in web Dynpro.
    Requirement is to set a DateType context Attribute with
    the value contained in the String ("20061102" ).
    Awaiting your kind responses..
    Regards,
    Mahesh

    SimpleDateFormat yyyyMMdd_parser = new SimpleDateFormat(
                   "yyyyMMdd");
    java.util.Date date=yyyyMMdd_parser.parse("20061102");
    java.sql.Date slqDate=new java.sql.Date(date.getTime());

  • Trying to convert String to java.sql.Date

    I need to convert a String (in the format "yyyy-mm-dd") to java.sql.Date
    It was suggested I use the following,
    SimpleDateFormat formater = new SimpleDateFormat("yyyy-mm-dd");
    Date result = formater.parse(dbirth.getText());
    However, It seem to produce a java.util.Date
    Error: found java.util.Date
    Required : java.sql.Date
    Can anyone help?
    Thanks, Marika

    I need to convert a String (in the format
    "yyyy-mm-dd") to java.sql.Date
    It was suggested I use the following,
    SimpleDateFormat formater = new
    SimpleDateFormat("yyyy-mm-dd");
    Date result = formater.parse(dbirth.getText());
    However, It seem to produce a java.util.Date
    Error: found java.util.Date
    Required : java.sql.Date
    Can anyone help?
    Thanks, Marika SimpleDateFormat formater = new SimpleDateFormat("yyyy-mm-dd");
    java.util.Date parsedDate = formater.parse(dbirth.getText());
    java.sql.Date result = new java.sql.Date(parsedDate.getTime());

  • Convert string into java.sql.Date

    Hi,
    I want to convert a date in string form into java.sql.Date to persist into the database column with Date as its datatype in Oracle. I'm trying as follows:
    import java.sql.Date;
    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    public class DateTest
    public static void main(String[] args)
    String strDate = "2002-07-16 14:45:01";
         System.out.println("strDate = "+strDate);
    Date aDate = null;
    try
    if(strDate != null && !strDate.trim().equals(""))
         SimpleDateFormat aSDF = new SimpleDateFormat();
         aSDF.applyPattern("yyyy-MM-dd hh:mm:ss");
         java.util.Date utilDate = aSDF.parse(strDate);
    System.out.println("utildate = "+utilDate);
         aDate = new Date(utilDate.getTime());
         aDate.setTime(utilDate.getTime());      
         System.out.println("aDate = "+aDate);
    catch (ParseException e)
    System.out.println("Unable to parse the date - "+strDate);
    catch (Exception ex)
    ex.printStackTrace();
    System.out.println("Caught Exception :"+ex.getMessage());
    It gives the output as :
    strDate = 2002-07-16 14:45:01
    utildate = Tue Jul 16 14:45:01 IST 2002
    aDate = 2002-07-16
    If I put this value into the database table, I can see only the date. Time part is missing. Is this the problem with java.sql.Date or Oracle datatype Date? Please help me asap.
    Thanks in advance.
    Regards,
    Rajapriya.R.

    If I put this value into the database table, I can
    see only the date. Time part is missing. Is this the
    problem with java.sql.Date or Oracle datatype Date?This is not a problem, this is the defined behaviour of the Date type. RTFAPI and have a look at Timestamp, while you're at it.

  • Java.sql.Date vs java.util.Date vs. java.util.Calendar

    All I want to do is create a java.sql.Date subclass which has the Date(String) constructor, some checks for values and a few other additional methods and that avoids deprecation warnings/errors.
    I am trying to write a wrapper for the java.sql.Date class that would allow a user to create a Date object using the methods:
    Date date1 = new Date(2003, 10, 7);ORDate date2 = new Date("2003-10-07");I am creating classes that mimic MySQL (and eventually other databases) column types in order to allow for data checking since MySQL does not force checks or throw errors as, say, Oracle can be set up to do. All the types EXCEPT the Date, Datetime, Timestamp and Time types for MySQL map nicely to and from java.sql.* objects through wrappers of one sort or another.
    Unfortunately, java.sql.Date, java.sql.Timestamp, java.sql.Time are not so friendly and very confusing.
    One of my problems is that new java.sql.Date(int,int,int); and new java.util.Date(int,int,int); are both deprecated, so if I use them, I get deprecation warnings (errors) on compile.
    Example:
    public class Date extends java.sql.Date implements RangedColumn {
      public static final String RANGE = "FROM '1000-01-01' to '8099-12-31'";
      public static final String TYPE = "DATE";
       * Minimum date allowed by <strong>MySQL</strong>. NOTE: This is a MySQL
       * limitation. Java allows dates from '0000-01-01' while MySQL only supports
       * dates from '1000-01-01'.
      public static final Date MIN_DATE = new Date(1000 + 1900,1,1);
       * Maximum date allowed by <strong>Java</strong>. NOTE: This is a Java limitation, not a MySQL
       * limitation. MySQL allows dates up to '9999-12-31' while Java only supports
       * dates to '8099-12-31'.
      public static final Date MAX_DATE = new Date(8099 + 1900,12,31);
      protected int _precision = 0;
      private java.sql.Date _date = null;
      public Date(int year, int month, int date) {
        // Deprecated, so I get deprecation warnings from the next line:
        super(year,month,date);
        if(! isWithinRange(this))
          throw new ValueOutOfRangeException((RangedColumn)this, "" + this);
      public Date(String s) {
        super(0l);
        // Start Cut-and-paste from java.sql.Date.valueOf(String s)
        int year;
        int month;
        int day;
        int firstDash;
        int secondDash;
        if (s == null) throw new java.lang.IllegalArgumentException();
        firstDash = s.indexOf('-');
        secondDash = s.indexOf('-', firstDash+1);
        if ((firstDash > 0) & (secondDash > 0) & (secondDash < s.length()-1)) {
          year = Integer.parseInt(s.substring(0, firstDash)) - 1900;
          month = Integer.parseInt(s.substring(firstDash+1, secondDash)) - 1;
          day = Integer.parseInt(s.substring(secondDash+1));
        } else {
          throw new java.lang.IllegalArgumentException();
        // End Cut-and-paste from java.sql.Date.valueOf(String s)
        // Next three lines are deprecated, causing warnings.
        this.setYear(year);
        this.setMonth(month);
        this.setDate(day);
        if(! isWithinRange(this))
          throw new ValueOutOfRangeException((RangedColumn)this, "" + this);
      public static boolean isWithinRange(Date date) {
        if(date.before(MIN_DATE))
          return false;
        if(date.after(MAX_DATE))
          return false;
        return true;
      public String getRange() { return RANGE; }
      public int getPrecision() { return _precision; }
      public String getType() { return TYPE; }
    }This works well, but it's deprecated. I don't see how I can use a java.util.Calendar object in stead without either essentially re-writing java.sql.Date almost entirely or losing the ability to be able to use java.sql.PreparedStatement.get[set]Date(int pos, java.sql.Date date);
    So at this point, I am at a loss.
    The deprecation documentation for constructor new Date(int,int,int)says "instead use the constructor Date(long date)", which I can't do unless I do a bunch of expensive String -> [Calendar/Date] -> Milliseconds conversions, and then I can't use "super()", so I'm back to re-writing the class again.
    I can't use setters like java.sql.Date.setYear(int) or java.util.setMonth(int) because they are deprecated too: "replaced by Calendar.set(Calendar.DAY_OF_MONTH, int date)". Well GREAT, I can't go from a Date object to a Calendar object, so how am I supposed to use the "Calendar.set(...)" method!?!? From where I'm sitting, this whole Date deprecation thing seems like a step backward not forward, especially in the java.sql.* realm.
    To prove my point, the non-deprecated method java.sql.Date.valueOf(String) USES the DEPRECATED constructor java.util.Date(int,int,int).
    So, how do I create a java.sql.Date subclass which has the Date(String) constructor that avoids deprecation warnings/errors?
    That's all I really want.
    HELP!

    I appreciate your help, but what I was hoping to accomplish was to have two constructors for my java.sql.Date subclass, one that took (int,int,int) and one that took ("yyyy-MM-dd"). From what I gather from your answers, you don't think it's possible. I would have to have a static instantiator method like:public static java.sql.Date createDate (int year, int month, int date) { ... } OR public static java.sql.Date createDate (String dateString) { ... }Is that correct?
    If it is, I have to go back to the drawing board since it breaks my constructor paradigm for all of my 20 or so other MySQL column objects and, well, that's not acceptable, so I might just keep my deprecations for now.
    -G

  • Add one day to java.sql.date

    I ask user to enter a date: yyyy-mm-dd, then I want to add one day to that date, I don't know how to do it?
    java.sql.Date time2 = java.sql.Date.valueOf( args[0] );
    Many Thanks.

    since a date object is really nothing more than a long you can always add one day's worth of milliseconds to it....
    long milliInADay = 1000 * 60 * 60 * 24;
    Date d = ......
    d.setTime(d.getTime() + milliInADay);although there may be some issues with this i'm unaware of, but seems pretty straightforward to me.

  • Java.sql.Date and java.util.Date - class loaded first in the classpath

    I had two jar files which has java.util.Date and java.sql.Date class file. i want to know whether which class is loaded first in the classpath...
    I like to change the order of loading the class at runtime...
    Is there is any way to change the order of loading of class...
    I may have different version of jar files for example xerces,xercesImpl. some of the code uses xerces ,some of the code uses xercesImpl..i had common classes.
    I like to load the class with the same name according to the order i need..
    Can we do all these in Run time ?????

    I had two jar files which has java.util.Date and
    java.sql.Date class file. i want to know whether
    which class is loaded first in the classpath...
    I like to change the order of loading the class at
    runtime...
    Is there is any way to change the order of loading of
    class...
    I may have different version of jar files for example
    xerces,xercesImpl. some of the code uses xerces ,some
    of the code uses xercesImpl..i had common classes.
    I like to load the class with the same name according
    to the order i need..
    Can we do all these in Run time ?????That is meaningless.
    The classes you are referring to are part of the Java API. Third party jars have no impact on that. And you can't change to the order because java.sql.Data is derived from java.util.Date. So the second must load before the first.
    And if you have two jar files with those classes in them (and not classes that use them) then you either should already know how to use them or you should stop trying to do whatever you are doing because it isn't going to work.

  • Put java.sql.Date in correct format

    I need to put java.sql.Date in correct format to query an Oracle database.
    Here is my code:
            SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yy");
            java.util.Date dateChosen = jXDatePicker1.getDate();
            String strDate = formatter.format(dateChosen);
            System.out.println("Date Chosen: " + strDate); // output is: 11-Feb-00
            java.util.Date parserDate = null;      
            try {
                parserDate = formatter.parse(strDate);
            } catch (ParseException re) {
                System.err.println("Exception caught: " + re.getMessage());
            // create java.sql.Date object
                java.sql.Date oraDate = new java.sql.Date(parserDate.getTime());
            System.out.println(oraDate);  // date is in this format: 2000-02-11
            System.out.println("formatted oraDate: " + formatter.format( oraDate ) ); // no good, stringIf I use formatter.format( oraDate ) I get the correct format (11-Feb-00) BUT it is no longer a sql Date, it is a String which can't be use.
    I have looked at the API and many other forum threads on this, any help would be greatly appreciated!

    In the class with the PreparedStatement, I pass the date like this:
    public class report extends javax.swing.JDialog {
         java.sql.Date newDate;
        public report(java.sql.Date passedOraDate, String passedtxtDate) {
            super();
            initComponents();
            setTitle("Report");
            setModal(true);
            newDate = passedOraDate;
            statusLabel.setText(passedtxtDate);
            System.out.println("passedtxtDate: " +passedtxtDate);       
            System.out.println("newDate: " +newDate);      
        }Here is the code that uses the actual PreparedStatement:
            try {
                // In my actual code I have all columns listed in query
                String query = "SELECT * FROM report WHERE repdate = ?";
                ps = conn.prepareStatement(query); // create a statement
                           ps.setDate(1, newDate); // set input parameter
                rs = ps.executeQuery();
                // extract data from the ResultSet
                ResultSetMetaData md = rs.getMetaData();
                int columns = md.getColumnCount();This is greatly edited to show relevant code!

  • Cannot find symbl method update Date(int,java.util.Date)

    I get following error
    cannot find symbl method update Date(int,java.util.Date) on compling class called GuestDataBean at line ( rowSet.updateDate( 4, guest.getDate() ); ).
    GustBean.java. I need help on why I get it.
    // JavaBean to store data for a guest in the guest book.
    package com.deitel.jhtp6.jsp.beans;
    import java.util.*;
    public class GuestBean
       private String firstName;
       private String lastName;
       private String email;
       private Date date;
       private String message;
       //Constructors
       public GuestBean(){
            public GuestBean(String firstname, String lastname, String email,Date date,String message){
                 this.firstName=firstname;
                 this.lastName=lastName;
                 this.email=email;
                 this.date=date;
                 this.message=message;
       // set the guest's first name
       public void setFirstName( String name )
          firstName = name; 
       } // end method setFirstName
       // get the guest's first name
       public String getFirstName()
          return firstName; 
       } // end method getFirstName
       // set the guest's last name
       public void setLastName( String name )
          lastName = name; 
       } // end method setLastName
       // get the guest's last name
       public String getLastName()
          return lastName; 
       } // end method getLastName
       // set the guest's email address
       public void setEmail( String address )
          email = address;
       } // end method setEmail
       // get the guest's email address
       public String getEmail()
          return email; 
       } // end method getEmail
       public void setMessage( String mess)
          message = mess;
       } // end method setEmail
       // get the guest's email address
       public String getMessage()
          return message; 
       } // end method getEmail
       public void setDate( Date dat )
          date = dat;
       } // end method setEmail
       // get the guest's email address
       public Date getDate()
          return date; 
       } // end method getEmail
    } // end class GuestBean
    GuestDataBean.java/**
    * @(#)GuestDataBean.java
    * @author
    * @version 1.00 2008/7/18
    // Class GuestDataBean makes a database connection and supports
    // inserting and retrieving data from the database.
    package com.deitel.jhtp6.jsp.beans;
    import java.sql.SQLException;
    import javax.sql.rowset.CachedRowSet;
    import java.util.ArrayList;
    import com.sun.rowset.CachedRowSetImpl; // CachedRowSet implementation
    import java.sql.*;
    public class GuestDataBean
       private CachedRowSet rowSet;
       // construct TitlesBean object
       public GuestDataBean() throws Exception
          // load the MySQL driver
          Class.forName( "org.gjt.mm.mysql.Driver" );
          // specify properties of CachedRowSet
          rowSet = new CachedRowSetImpl(); 
          rowSet.setUrl( "jdbc:mysql://localhost:3306/virsarmedia" );
          rowSet.setUsername( "root" );
          rowSet.setPassword( "" );
           // obtain list of titles
          rowSet.setCommand(
             "SELECT firstName, lastName, email,date,message FROM guest" );
          rowSet.execute();
       } // end GuestDataBean constructor
       // return an ArrayList of GuestBeans
       public ArrayList< GuestBean > getGuestList() throws SQLException
          ArrayList< GuestBean > guestList = new ArrayList< GuestBean >();
          rowSet.beforeFirst(); // move cursor before the first row
          // get row data
          while ( rowSet.next() )
             GuestBean guest = new GuestBean();
             guest.setFirstName( rowSet.getString( 1 ) );
             guest.setLastName( rowSet.getString( 2 ) );
             guest.setEmail( rowSet.getString( 3 ) );
             guest.setDate( rowSet.getDate( 4 ) );
             guest.setMessage( rowSet.getString( 5 ) );
             guestList.add( guest );
          } // end while
          return guestList;
       } // end method getGuestList
       // insert a guest in guestbook database
       public void addGuest( GuestBean guest ) throws SQLException
          rowSet.moveToInsertRow(); // move cursor to the insert row
          // update the three columns of the insert row
          rowSet.updateString( 1, guest.getFirstName() );
          rowSet.updateString( 2, guest.getLastName() );
          rowSet.updateString( 3, guest.getEmail() );
          rowSet.updateDate( 4, guest.getDate() );
          rowSet.updateString( 5, guest.getMessage() );
          rowSet.insertRow(); // insert row to rowSet
          rowSet.moveToCurrentRow(); // move cursor to the current row
          rowSet.commit(); // propagate changes to database
       } // end method addGuest
    } // end class GuestDataBean

    This isn't a JSP question, it better belongs in the JavaProgramming, or JDBC forums.
    But the problem is because the updateDate method uses a java.sql.Date object and you are giving it a java.util.Date object. You have to convert from java.util.Date to java.sql.Date. See: [the api for java.sql.Date|http://java.sun.com/javase/6/docs/api/java/sql/Date.html] .
    Edited by: stevejluke on Jul 21, 2008 5:43 PM

Maybe you are looking for