Wrox Programmer Forums
|
Java Databases Discussion specific to working with Java Databases. For other Java topics, please see related Java forums. For database discussions not specific to Java, please see the Database category.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 20th, 2007, 08:31 AM
Registered User
 
Join Date: Jul 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Timestamp Problem

Hello all, how r u ? wishing all the best of luck.
I have a problem with Timestamp.
this is the problem :
I have a DB Oracle 10g, and i made a query to return fields from the DB ( fields were : date1 as Date & load as Number) and the rows returned with some parameters are :
     date1 load
    DD/MM/YYYY
1 - 01/05/2007 0.0
2 - 02/05/2007 2.6
3 - 03/05/2007 8.3
4 - 04/05/2007 10.9

when inserting this statement in java code and return rows in ResultSet, I made 2 objects : Timestamp/Date for date1 and BigDecimal for load and the result is:
1 - 01/05/2007 00:00:00 0.0 // it is OK
2 - 02/05/2007 00:00:00 2.6 // it is OK
3 - 02/05/2007 23:00:00 8.3 // ERROR
4 - 04/05/2007 00:00:00 10.9 ( not 03/05/2007 )

PLZ, if any one can help me in this problem and thanks alot.
 
Old September 23rd, 2007, 02:16 AM
Registered User
 
Join Date: Jul 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Why NO Reply ???

 
Old September 23rd, 2007, 11:18 PM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 373
Thanks: 0
Thanked 1 Time in 1 Post
Default

try using java.sql.Date, like resultSetObject.getDate(1) and use it. If you've posted little code it'd been little helpful.

- Rakesh
 
Old September 24th, 2007, 01:00 AM
Registered User
 
Join Date: Jul 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

when i select a date and a number from Datebase in TOAD for Oracle Application as
select date1, load from c_day
the result is :
date1 ( type Date ) load ( type Number)
DD/MM/YYYY
01/05/2007 20.30
02/05/2007 16.21
03/05/2007 65.014
04/05/2007 20.30

when inserting this query in Java Code as:
Timestamp t = null;
BigDecimal b = null;
String sql = "select date1, load from c_day";
PreparedStatement stm = con.prepareStatement(sql);
ResultSet rs = stm.executeQuery();
while(rs.next){
t = rs.getTimestamp(1);
b = rs.getBigDecimal(2);
System.out.println("date : " + t.toString() + " , load = " + b.doubleValue());
}
// some dates is wrong .
Result
date : 01/05/2007 00:00:00 , load = 20.30
date : 02/05/2007 00:00:00 , load = 16.21
date : 02/05/2007 23:00:00 , load = 65.014
date : 04/05/2007 00:00:00 , load = 20.30
 
Old September 26th, 2007, 07:09 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 373
Thanks: 0
Thanked 1 Time in 1 Post
Default

Check the article on Date data type at the following link
http://www.tar.hu/sqlbible/sqlbible0023.html

According to that article Date type also holds time information. May be the date1 column has that time information stored for row 3 in your table. That is why the time is been given as 23:00:00.
If you are using date1 column to store only date the change the java code like

Code:
t = rs.getDate(1); instead of using t = rs.getTimestamp(1);



- Rakesh
 
Old September 26th, 2007, 07:51 AM
Registered User
 
Join Date: Jul 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

when using rs.getDate(1) , it returned the following :
date1 = 01/05/2007 , load ...
date1 = 02/05/2007 , load ...
date1 = 02/05/2007 , load ...
date1 = 04/05/2007 , load ...





Similar Threads
Thread Thread Starter Forum Replies Last Post
TimeStamp nay_ctg BOOK: Beginning Cryptography with Java 1 August 7th, 2008 07:37 PM
Timestamp display problem nareshphp PHP Databases 1 August 9th, 2007 12:20 AM
GridView + timestamp victorsj ASP.NET 2.0 Professional 0 August 29th, 2006 10:41 AM
timestamp isheikh BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 1 November 18th, 2004 06:23 PM
UNIX Timestamp apek PHP How-To 4 January 20th, 2004 02:05 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.