This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes JDBC 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 EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
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: 300

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(
at com.mysql.jdbc.SQLError.createSQLException(

Please tell me where i am wrong.

Jeanne Boyarsky
internet detective

Joined: May 26, 2003
Posts: 29219

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.

[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
I agree. Here's the link:
subject: Bad format for Time
Similar Threads
query is not getting executed
Queries and "column not found" error
JDBC throws exception on java app detach from console
JBM-Tables not created.
Mysql driver fails on connection