Results 1 to 3 of 3
  1. #1
    Dave is offline Member
    Join Date
    Jul 2008
    Posts
    2
    Rep Power
    0

    Default saving date and time in a derby database from an ejb module

    Hello,
    I can easily save and retrieve a date from an ejb application (creating a derby table with Date as one of the fields - automatically generating the entity class, -creating a session facade bean and creating a client) - but if the date also contains a time the time doesn't seemed to get stored in the table. I used DateFormat df = DateFormat.getDateTimeInstance();
    df.parse("15-Jun-2009 14:19:50") in the client
    I know the session bean gets the date and time, but when I retrieve the date/time from the table I only get the date - not the time. Does anybody know how to do this or point me to an example which will show me?
    Thank you
    Dave

  2. #2
    linuxswan is offline Member
    Join Date
    Mar 2008
    Posts
    28
    Rep Power
    0

    Default

    import java.text.DateFormat;
    import java.text.ParseException;
    import java.util.Date;

    public class DateFormatExample2 {

    public static void main(String[] args) {
    // Make a String that has a date in it, with MEDIUM date format
    // and SHORT time format.
    String dateString = xxxxxxxxxxx

    " retrieve the datestring from the database for example - Nov 4, 2003 8:14 PM i.e the connection settings from the database and etc., Connection, Statement, ResultSet"

    // Get the default MEDIUM/SHORT DateFormat
    DateFormat format =
    DateFormat.getDateTimeInstance(
    DateFormat.MEDIUM, DateFormat.SHORT);

    // Parse the date
    try {
    Date date = format.parse(dateString);
    System.out.println("Original string: " + dateString);
    System.out.println("Parsed date : " +
    date.toString());
    }
    catch(ParseException pe) {
    System.out.println("ERROR: could not parse date in string \"" +
    dateString + "\"");
    }


    Ok this logic or the example program will help you

    i hope you will get the results
    Last edited by linuxswan; 07-19-2008 at 09:58 AM.

  3. #3
    Dave is offline Member
    Join Date
    Jul 2008
    Posts
    2
    Rep Power
    0

    Smile solution to problem

    Hi, I've solved my problem. The problem was that it wasn't saving time information to the database table where the column was of type Date, it just saved the date part not the time. When net beans generated the entity classes form the database the temporal annotation that was added was @Temporal(TemporalType.DATE) when I changed this to @Temporal(TemporalType.TIMESTAMP) everthing worked fine. Thanks to everybody who posted a reply
    Dave

Similar Threads

  1. Formatting time and date
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-17-2008, 08:35 PM
  2. Date/Time Servlet
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-14-2008, 10:34 AM
  3. File creating date/time
    By bugger in forum New To Java
    Replies: 1
    Last Post: 11-11-2007, 08:43 PM
  4. Time and Date in Java
    By java_fun2007 in forum New To Java
    Replies: 4
    Last Post: 11-06-2007, 08:25 PM
  5. how to get the current date and time
    By valery in forum New To Java
    Replies: 1
    Last Post: 08-03-2007, 07:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •