File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes help with DateTime overflow exception- please!!!!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "help with DateTime overflow exception- please!!!!!!" Watch "help with DateTime overflow exception- please!!!!!!" New topic

help with DateTime overflow exception- please!!!!!!

Paula Vasseur

Joined: Feb 16, 2003
Posts: 5
I have written the following code for getting a day, month year and time from a form and inserting this into a table in Access, but always get the
errorjava.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver]Datetime field overflow (null)
Also how would I get this code to update a table which already has the date and time inserted into it?
Thanks for your help, this is really cracking me up and am going to throw the computer out the window soon!!!
Slainte Paula
The code is as follows:
<%--set the content type, import the java.sql classes, include a file containing a page heading--%>
<%@page contentType="text/html"%>
<%@page import="java.sql.*"%>
<%@page import="java.text.*"%>
<%@page import="java.util.Calendar"%>
<%@page import="java.lang.String"%>
<%--start the html--%>
<CENTER><H3>Book an appointment H3></CENTER>
<%--set up variables for the sql statement, the connection to the database,
and the results --%>
String driverName = "sun.jdbc.odbc.JdbcOdbcDriver";
String connectionURL = "jdbc dbc:Vet";
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
PreparedStatement ps = null;
int day= 0;
int month = 0;
int year = 0;
int hour = 0;
int mins = 0;
//Calendar c= new Calendar();
Calendar c = Calendar.getInstance();
c.set(year, month, day, hour, mins);
Date appoint_Date = new Date(c.getTime().getTime());
Time appoint_Time = new Time(c.getTime().getTime());
//make the database connection
con = DriverManager.getConnection(connectionURL);
ps = con.prepareStatement("INSERT INTO appoints1 (appoint_Date, appoint_Time) values (?,?)");
ps.setDate(1, appoint_Date);
ps.setTime(2, appoint_Time);
if (ps != null) {
catch (Exception e){
%><%= e %>
//print out the results

//close the database
if (con != null) {
catch(Exception e) {%>
<%= e %>
<%--close the html --%>
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
I'm moving this to The JDBC Forum...

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33107

Are you setting year, month, day, etc to anything before putting the value in the database? If everything is set to zero, that would be dawn of time. Some databases may not be able to handle that value.

[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:
subject: help with DateTime overflow exception- please!!!!!!
It's not a secret anymore!