jQuery in Action, 3rd edition
The moose likes JDBC and Relational Databases and the fly likes  Bad format for Time Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark " Bad format for Time" Watch " Bad format for Time" New topic

Bad format for Time

pankaj semwal
Ranch Hand

Joined: Oct 07, 2008
Posts: 303

I have a query like this select TIMEDIFF(TIME(al.login_time),CURTIME()) AS currDuration ") ;

It return correct time diffrence when i run this query in mysql prompt.

But when i use query in java code :
and try to get time difference

like this resultSet.getString("currDuration");

Its show excpetion :

java.sql.SQLException: java.sql.SQLException: Bad format for Time '-10:02:47' in column 1
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)

Please tell me where i am wrong.

Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 32819

It is good practice to use one of getDate(), getTime() and getTimeStamp() rather than getString(). That way your database can handle the conversion for you.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
I agree. Here's the link: http://aspose.com/file-tools
subject: Bad format for Time
It's not a secret anymore!