Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

SQL statement fails in Java

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

This SQL statement works in MYSQL workbench.



END and START are times of the day in 24hr format e.g. 2300. The code prevents negative values when calculating a time difference. For example:

START 0600 END 0800 Using END-START the answer is 2

START 2200 END 0200 Using END-START the answer is -20 Not correct. The if statement corrects this and outputs 4

However the statement fails and throws an exception when I run in Java.



What is the correct Java code?

Thanks,
RJ.
 
Saloon Keeper
Posts: 6525
160
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Post the full exception stack trace.
 
Robbie James
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The exception comes from a try catch block. The following message is displayed "An error has occurred during the Statement phase". See below for more info.


 
Tim Moores
Saloon Keeper
Posts: 6525
160
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Put "e.printStackTrace();" into the catch block so that the stack trace is printed out.

I notice that there's a "GROUP BY DATE" but no column DATE gets defined.
 
Robbie James
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for that.

It says column DATE not found. I checked the spelling and this column is present in the table.

 
Tim Moores
Saloon Keeper
Posts: 6525
160
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's generally not a good idea to use SQL keywords as names for anything. MY SQL is rusty, but you may need to select it in order to use it in a GROUP BY clause, something like

SELECT date, IF (((END-START)<0), (((2400-START)/100)+(END/100)), (END-START)) As TotalCount FROM `log_entries` GROUP BY DATE asc
   
 
Robbie James
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Tim. Much appreciated.
 
Would you turn that thing down? I'm controlling a mind here! Look ... look at the tiny ad ...
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic