Results 1 to 3 of 3
- 07-17-2008, 04:52 PM #1
Member
- Join Date
- Jul 2008
- Posts
- 2
- Rep Power
- 0
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
- 07-19-2008, 08:45 AM #2
Member
- Join Date
- Mar 2008
- Posts
- 28
- Rep Power
- 0
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 resultsLast edited by linuxswan; 07-19-2008 at 08:58 AM.
- 07-22-2008, 11:14 AM #3
Member
- Join Date
- Jul 2008
- Posts
- 2
- Rep Power
- 0
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
-
Formatting time and date
By Java Tip in forum java.langReplies: 0Last Post: 04-17-2008, 07:35 PM -
Date/Time Servlet
By Java Tip in forum Java TipReplies: 0Last Post: 01-14-2008, 09:34 AM -
File creating date/time
By bugger in forum New To JavaReplies: 1Last Post: 11-11-2007, 07:43 PM -
Time and Date in Java
By java_fun2007 in forum New To JavaReplies: 4Last Post: 11-06-2007, 07:25 PM -
how to get the current date and time
By valery in forum New To JavaReplies: 1Last Post: 08-03-2007, 06:05 PM


LinkBack URL
About LinkBacks

Bookmarks