This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes JDBC supported SQL functions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "JDBC supported SQL functions" Watch "JDBC supported SQL functions" New topic

JDBC supported SQL functions

jam hall

Joined: Sep 06, 2005
Posts: 4
Im using JDBC to connect to a MS Access database. I've tried to execute a query using the 'MONTHS_BETWEEN' function. An SQL exception was thrown saying it didnt like the function. Anyone know how i might be able to run this query through JDBC. I suspect i might need to change to a oracle DB.

Thanks Ahead
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24183

JDBC itself doesn't support any SQL functions, or anything else, for that matter. All such support is offered by the underlying database, or the driver for that database. I'm not familiar with this function you mention, but if it's not supported by MS Access, then you won't be able to use it via JDBC connected to MS Access.

[Jess in Action][AskingGoodQuestions]
Jayesh Lalwani
Ranch Hand

Joined: Nov 05, 2004
Posts: 502
Access doesn't support MONTH_BETWEEN. You have to use the dateDiff dunction for Access.

You can refer to this page for differrences between Oracle and Microsoft Access SQL
jam hall

Joined: Sep 06, 2005
Posts: 4
I've tried using DATEDIFF, here is my code

System.out.print("enter date");
String date =;
Statement statement = link.createStatement();
results = statement.executeQuery("SELECT refNo ,DATEDIFF('Month','"+date+"','dateOf') FROM tblFault");

I get a datatype mismatch error. Does the date that the user enters need to be in a date object?

Any help would be much apreciated

Thanks ahead
Jayesh Lalwani
Ranch Hand

Joined: Nov 05, 2004
Posts: 502
What's dateOf ? Is that a column in your tblFault table

try this

For the above statement to work, the format of your date should be same as the format of the date in the database. If the format is differrent you will have to use the CONVERT operator to convert string into datetime
jQuery in Action, 2nd edition
subject: JDBC supported SQL functions
Similar Threads
Oracle date-time fields
java.sql.SQLException: ORA-00932: inconsistent datatypes: expected NUMBER got DATE
How to make a query faster.
JDBC doesn't retrieve all the results available in the MSSQL database
converting from Hibernate to JDBC???