java.sql.SQLException: Bad format for Time

Hi,

I'm trying to get the TIMEDIFF from a saved TIME in my database and I get this error, but I dont know in which format to get in in order to get it right.

Here's my code:

String checkElectionTime =""

+"Select TIMEDIFF(ElectionDate, CURRENT_TIMESTAMP ) as DiffTime "

+"From dz304_system.Elections "

+"where ElectionID='"+id+"'";

Statement stmt3 = con2.createStatement();

ResultSet rs2=stmt3.executeQuery(checkElectionTime);

rs2.next();

String diffTime = rs2.getString(1);

The exact error:

javax.servlet.ServletException: java.sql.SQLException: Bad format for Time '1873:53:58' in column 1

So I do get the timediff correctly it just cannot be passed to String right?

Any Ideas on how to resolve this?

Thank you

[942 byte] By [despinaa] at [2007-11-26 21:54:21]
# 1
The stack trace tells you the exact line that the error occurs on - don't guess.What is the data type of the ElectionDate column?Most perhaps all JDBC drivers will attempt to return any value as a string. That includes time type values.
jschella at 2007-7-10 3:49:08 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2
The error is on line:String diffTime = rs2.getString(1);when I try to get the Time. ElectionDate on database is of type datetime
despinaa at 2007-7-10 3:49:08 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3
Odd. No idea.One solution would be that since you are extracting it as a string anyways just explicitly convert it to a varchar in the sql.
jschella at 2007-7-10 3:49:08 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 4
Hi,There is no error on that line, see the subsequent lines.Regards,Ram.
JTecha at 2007-7-10 3:49:08 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 5
Is it possible that it's tomcat's fault? because I have the exact same code on another server running, and I get no errors.
despinaa at 2007-7-10 3:49:08 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 6

> Is it possible that it's tomcat's fault? because I

> have the exact same code on another server running,

> and I get no errors.

Unlikely. It's your code and it is causing the database to return that exception, which is caused by some data in the database. The fact that it's running in Tomcat shouldn't make any difference.

So I would question whether you really have the exact same code running without errors in another server. Does this exact same code query the exact same data with the exact same parameters?

DrClapa at 2007-7-10 3:49:08 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 7

Yes, they are exactly the same.

I had them running on my hosting website and I copied the files to work locally on my computer and when I tried to run them I get this error.

The tables are copied as well

By the way, it might worth mentioning that I'm trying a similar code:

String checkElectionDate = ""

+"Select DATEDIFF(ElectionDate, CURRENT_TIMESTAMP ) as Diff "

+"From dz304_system.Elections "

+"where name='"+elections1+"'";

Statement stamt = con2.createStatement();

ResultSet res = stamt.executeQuery(checkElectionDate);

res.next();

String diff = res.getString("Diff");

and it works fine

Message was edited by:

despina

despinaa at 2007-7-10 3:49:08 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 8

> Yes, they are exactly the same.

> I had them running on my hosting website and I copied

> the files to work locally on my computer and when I

> tried to run them I get this error.

No you are assuming they are the same.

Basically the only way to insure that they are the same is take the server down, clear out ALL of the jars (wars, etc), clean out your build directly entirely, rebuild from scratch, reinstall, start the server.

Did you do all of that?

If not they you are assuming and nothing more.

jschella at 2007-7-10 3:49:08 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 9
Ok... So it can be server's fault then?When I say files, I mean the file with my code in, that is the file aving these exact lines in.
despinaa at 2007-7-10 3:49:08 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 10

> Ok... So it can be server's fault then?

> When I say files, I mean the file with my code in,

> that is the file aving these exact lines in.

When the code is running in the server then the server is running a class file.

That class file does not necessarily match your source file.

What I suggested insures that it does match. You don't have to do that but then you run the risk that they do not match.

jschella at 2007-7-10 3:49:08 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...