Unix Technical Forum

datetime JDBC date conversion

This is a discussion on datetime JDBC date conversion within the SQL Server forums, part of the Microsoft SQL Server category; --> I am writing a datetime field value to MS SQL Server 7 in the following manner via a stored ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-29-2008, 05:39 AM
billb
 
Posts: n/a
Default datetime JDBC date conversion

I am writing a datetime field value to MS SQL Server 7 in the following manner
via a stored procedure:

// item to be written is originally a java.util.Date object
java.util.Date fromDate;
// I'm inserting it here into the database
cstmt.setTimestamp(8, new Timestamp(fromDate.getTime()));

// the record in the database appears as follows - as I wanted it to..
12/23/2004 4:30:43 AM

The problem is reading the date FROM the database back into ANY type of Java
Date-related object. No matter what I try, the hour/minutes/seconds are not
returned, and I desperately need the hour and minutes. I don't want to store
the hours and minutes in another field - it just causes more complications.
Does anyone out there know a way to get the ENTIRE date value out of the database?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-29-2008, 05:39 AM
John Bell
 
Posts: n/a
Default Re: datetime JDBC date conversion

Hi

Are you saying that getTime() returns 00:00:00 ?

Posting your the code that tries to retrive this may help!

John

"billb" <kmilburn@austin.rr.com> wrote in message
news:3561fddb.0410261050.6c8bafba@posting.google.c om...
> I am writing a datetime field value to MS SQL Server 7 in the following

manner
> via a stored procedure:
>
> // item to be written is originally a java.util.Date object
> java.util.Date fromDate;
> // I'm inserting it here into the database
> cstmt.setTimestamp(8, new Timestamp(fromDate.getTime()));
>
> // the record in the database appears as follows - as I wanted it to..
> 12/23/2004 4:30:43 AM
>
> The problem is reading the date FROM the database back into ANY type of

Java
> Date-related object. No matter what I try, the hour/minutes/seconds are

not
> returned, and I desperately need the hour and minutes. I don't want to

store
> the hours and minutes in another field - it just causes more

complications.
> Does anyone out there know a way to get the ENTIRE date value out of the

database?


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-29-2008, 05:40 AM
Joe Weinstein
 
Posts: n/a
Default Re: datetime JDBC date conversion



billb wrote:

> I am writing a datetime field value to MS SQL Server 7 in the following manner
> via a stored procedure:
>
> // item to be written is originally a java.util.Date object
> java.util.Date fromDate;
> // I'm inserting it here into the database
> cstmt.setTimestamp(8, new Timestamp(fromDate.getTime()));
>
> // the record in the database appears as follows - as I wanted it to..
> 12/23/2004 4:30:43 AM
>
> The problem is reading the date FROM the database back into ANY type of Java
> Date-related object. No matter what I try, the hour/minutes/seconds are not
> returned, and I desperately need the hour and minutes. I don't want to store
> the hours and minutes in another field - it just causes more complications.
> Does anyone out there know a way to get the ENTIRE date value out of the database?


Are you sure you tried getTimestamp()?
Joe Weinstein at BEA

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-29-2008, 05:40 AM
Mykola Rabchevskiy
 
Posts: n/a
Default Re: datetime JDBC date conversion

billb wrote:
> I am writing a datetime field value to MS SQL Server 7 in the following manner
> via a stored procedure:
>
> // item to be written is originally a java.util.Date object
> java.util.Date fromDate;
> // I'm inserting it here into the database
> cstmt.setTimestamp(8, new Timestamp(fromDate.getTime()));
>
> // the record in the database appears as follows - as I wanted it to..
> 12/23/2004 4:30:43 AM
>
> The problem is reading the date FROM the database back into ANY type of Java
> Date-related object. No matter what I try, the hour/minutes/seconds are not
> returned, and I desperately need the hour and minutes. I don't want to store
> the hours and minutes in another field - it just causes more complications.
> Does anyone out there know a way to get the ENTIRE date value out of the database?


Convert DATETIME into CHARATER using MS SQL finction is SELECT statement:

CONVERT ( VARCHAR( length ), some_datetime_colimn, <style> )

where <style> is magic number which defines format( 120 ~ yyyy-mm-dd HH:mi:ss);

get value from ResultSet as string and parse it using

java.text.DateFormat.parseDate(...)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-29-2008, 05:42 AM
Yasir Khan
 
Posts: n/a
Default Re: datetime JDBC date conversion

Hi,

Please use the following to construct a full date object from database date
field.

java.util.Date myDate = new
java.util.Date(myResultSet.getTimestamp("myDate"). getTime());

I hope this will help ..

Regards,
Yasir

"billb" <kmilburn@austin.rr.com> wrote in message
news:3561fddb.0410261050.6c8bafba@posting.google.c om...
> I am writing a datetime field value to MS SQL Server 7 in the following

manner
> via a stored procedure:
>
> // item to be written is originally a java.util.Date object
> java.util.Date fromDate;
> // I'm inserting it here into the database
> cstmt.setTimestamp(8, new Timestamp(fromDate.getTime()));
>
> // the record in the database appears as follows - as I wanted it to..
> 12/23/2004 4:30:43 AM
>
> The problem is reading the date FROM the database back into ANY type of

Java
> Date-related object. No matter what I try, the hour/minutes/seconds are

not
> returned, and I desperately need the hour and minutes. I don't want to

store
> the hours and minutes in another field - it just causes more

complications.
> Does anyone out there know a way to get the ENTIRE date value out of the

database?


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
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
Forum Jump


All times are GMT. The time now is 10:15 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com