This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes Wrong time retrieved in the resultset- MS SQL Server 2000 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Wrong time retrieved in the resultset- MS SQL Server 2000" Watch "Wrong time retrieved in the resultset- MS SQL Server 2000" New topic
Author

Wrong time retrieved in the resultset- MS SQL Server 2000

amod god
Greenhorn

Joined: Mar 17, 2009
Posts: 8
Hi,

I am using jtds-1.1.jar as a SQL Server Driver to connect to MS SQL Server
2000. I have the following 2 columns in a table.

Job_Start_Time(datetime,null) | Job_End_Time(datetime,null)
------------------------------------------------------------------------
1900-01-01 20:00:00.000 | 1900-01-02 04:00:00.000

When I try to retrieve this data using rs.getTime("Job_Start_Time") and
rs.getTime("Job_End_Time"), I am getting it 20:23:20 and 04:23:20
respectively.

Can anyone let me know the workaround or anything that I'm missing out on?

Thanks
-Amod
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Try to get them with rs.getString() or as a object and see whether the actual data has been fetched or not !


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
amod god
Greenhorn

Joined: Mar 17, 2009
Posts: 8
Hi Sagar,

Thanks for your reply.

I have checked that. Even, I have tried with rs.getTimestamp() but the result presists.

-Amod
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Does the time difference change, or is it always 23 minutes 20 seconds?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
amod god
Greenhorn

Joined: Mar 17, 2009
Posts: 8
Hi Paul,

Most of the times, it does. Generally, I retrieve these timings and display it on the web page(form). If I click on the save button, it saves 900-01-01 20:23:00.000 | 1900-01-02 04:23:00.000 in the database.

Sometimes, I do get 20:46 and 04:46 when I retrieve the same record. I'm watching that there is pattern(difference of 23)

I don't care about the seconds as of now.

Thanks
-Amod
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Is it 20:46:40 and 04:46:40?
amod god
Greenhorn

Joined: Mar 17, 2009
Posts: 8
No, it's 20:46:20 and 04:46:20.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Have you tried this with Microsoft's JDBC driver? jTDS does some work to produce a DateTime object - trying it with a different driver would be a quick test to see if there is a driver bug (though its not one I know of in jTDS).
amod god
Greenhorn

Joined: Mar 17, 2009
Posts: 8
Thanks Paul.

Let me check with that driver.

Regards
-Amod
amod god
Greenhorn

Joined: Mar 17, 2009
Posts: 8
Hey Paul,

It looks like we are through. My initial testing with Microsoft's driver is successful. But as per the requirement, I *have* to use the jTDS driver. Let me check with the later version of jTDS driver.

Thanks a lot for your suggestion.

Regards,
-Amod
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Interesting requirement! I suppose at least you can deliver your software exactly as specified with the error in it. I'd speak to whoever wrote the requirement and ask why jTDS is required. I can understand why you would use jTDS over the old MS SQL Server 2000 driver - it was bug ridden, largely unsupported (MS bough the code from someone else and had no legal rights to update it) and undistributable (for the same reason). But now of those issues exist with the newer driver.

Have you checked jTDS JIRA? They might have a patch.
amod god
Greenhorn

Joined: Mar 17, 2009
Posts: 8
Actually, the application is being integrated with the other one. So, we have to make sure that both the applications are using the same driver.(and its a JTDS ) I tried with jTDS1.2.2 jar file but the result remains the same.

I couldn't find any solution in JIRA. I will have to continue with my *research* on this.

Regards,
-Amod
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Please post the DDL of the table.

It would also be helpful if you cut down the whole thing into an SSCCE and post it here.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

amod god wrote:Actually, the application is being integrated with the other one. So, we have to make sure that both the applications are using the same driver.(and its a JTDS ) I tried with jTDS1.2.2 jar file but the result remains the same.

I couldn't find any solution in JIRA. I will have to continue with my *research* on this.

Regards,
-Amod


jTDS is open source. Have you tried debugging into the source? You may have stumbled on a genuine bug (though jTDS has been fairly stable for quite some time now).

Bauke - I'm guessing SSCCE stands for "Short Self-Contained Correct Example"?
amod god
Greenhorn

Joined: Mar 17, 2009
Posts: 8
Hi Paul and Bauk,

Now, this is very weird. I tried it by including the following line in the source code.

public Time getTime(int columnIndex) throws SQLException {
System.out.println("jtds time = "+Support.convert(this, getColumn(columnIndex), java.sql.Types.TIME, null));
return (java.sql.Time) Support.convert(this, getColumn(columnIndex), java.sql.Types.TIME, null);
}

And, it gives me the correct result. So I guess, Am I running into some jar conflict?

Thanks
-Amod
 
 
subject: Wrong time retrieved in the resultset- MS SQL Server 2000
 
Similar Threads
How to print all the fields in a record
default date?
SqlServ er
Scrollable ResultSet
How to identify Auth method NTLMv1 or NTLMv2