Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-17-2008, 06:52 PM
Member
 
Join Date: Jul 2008
Posts: 2
Dave is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-19-2008, 10:45 AM
Member
 
Join Date: Mar 2008
Posts: 28
linuxswan is on a distinguished road
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 10:58 AM.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-22-2008, 01:14 PM
Member
 
Join Date: Jul 2008
Posts: 2
Dave is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Formatting time and date Java Tip java.lang 0 04-17-2008 09:35 PM
Date/Time Servlet Java Tip Java Tips 0 01-14-2008 11:34 AM
File creating date/time bugger New To Java 1 11-11-2007 09:43 PM
Time and Date in Java java_fun2007 New To Java 4 11-06-2007 09:25 PM
how to get the current date and time valery New To Java 1 08-03-2007 08:05 PM


All times are GMT +3. The time now is 01:05 PM.


VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org