Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3403452
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:15:46+00:00 2026-05-18T05:15:46+00:00

My java class (servlet) has been running fine, but recently, I noticed a problem.

  • 0

My java class (servlet) has been running fine, but recently, I noticed a problem.

In my database, I have a Date column called ‘Full_Expiration_Date’. If one was entered it will store it like ‘2010-11-17’. If one wasn’t entered, is stores it like ‘0000-00-00’.

In my class, I call the records from the db, and look at the ‘Full_Expiration_Date’ field to see if it has a date or not. If it does, I execute a few lines of code that check to see if before today’s date, and if the date is NOT today’s date – if both those conditions are met, the coupon has expired.

So my code works just fine when there IS an expiration date specified, but fails when ‘0000-00-00’ is in the field.

I’m generating an array of information for each coupon in the db table. Once the checking is complete and the array is filled, its sent as a request attribute.

Here’s a snippet of my code for this process –

rs = stmt.executeQuery("select Full_Expiration_Date from coupons");

//will hold value from "Full_Expiration_Date" field in db
java.sql.Date expirationDate = null;

//today's date - used for comparison
java.util.Date today = new java.util.Date();  

while(rs.next()) {
    //get expiration date from db for this record
    expirationDate = rs.getDate(12);  

    if(expirationDate == null) { //should be if the field is 0000-00-00, right?
       //don't do any checking against
       //expiration date, this record 
       //doesn't have one
       couponList[counter][11] = "";
     } else { //10                         
       if(expirationDate.before(today) & !today.equals(expirationDate)) { 
          couponList[counter][11] = "expired";
           } else { //11
          couponList[counter][11] = "";
       }//if 
     }//if
   counter++;
  }//while   

Can someone pinpoint what I’m doing wrong here? I’m certain, after testing, that it has to do with the field being 0000-00-00.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T05:15:47+00:00Added an answer on May 18, 2026 at 5:15 am

    You can work around this using MySQL’s “zeroDateTimeBehavior” configuration property. In your connection properties set:

    “zeroDateTimeBehavior” to “convertToNull”

    Anytime a 0000-00-00 date is retrieved, it will return null instead of throwing an exception.

    Reference: http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference-configuration-properties.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Java .class files can be decompiled fairly easily. How can I protect my database
I have a java class: it.eng.ancona.view.RuoliView$TabElaborazioneFattureValidazione$ElencoDettaglioElaborazioneFattureValidazione$RigaElencoDettaglioElaborazioneFattureValidazione It's so long for multiple inner class. If
I have a java class which fires custom java events. The structure of the
I have a java class that applies an xslt to all xml files in
I have the following java class with the JAXB @XMLRootElement annotation @XmlRootElement(name=ClientData) public class
I once wrote this line in a Java class. This compiled fine in Eclipse
What are the consequences of running a Java class file compiled in JDK 1.4.2
The RFC for a Java class is set of all methods that can be
Imagine this sample java class: class A { void addListener(Listener obj); void removeListener(Listener obj);
What characters are valid in a Java class name? What other rules govern Java

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.