• 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
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Expiry date in java

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want something like that is, when I select a date from jDateChooser for adding a product into my database and jTable also and press ADD button it will give me a message that "the date you are selecting will be a expiry date for the product.please stay away from adding the product into your stock". I mean I can't add any product into my stock which date is already expired. For getting that result what logic I have to implement? I am a beginner of java. Anyone help me please.
 
Rancher
Posts: 1965
15
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you should look for Date comparison functions in java.
 
Marshal
Posts: 65102
247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Please explain more. Did you write the code all yourself? How is the expiry date set?
 
Rifa Ahmed
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome
I just write the code of ADD function. It adds the product with it's ID,name,price,date,image,quantity. But I want that thing which I posted. But I can't figure out what I need to do to get the result I wanted.
Here is my ADD function code,
 
Swastik Dey
Rancher
Posts: 1965
15
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So what exact result do you want? The selected date should not go forward or backward beyond a specific limit?
 
Rifa Ahmed
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes the date will be limit like 2010-01-01 so that when I am going to add a product by choosing date 1990-01-01 from the jdateChooser it will prevent me to add that expiry product.
 
Swastik Dey
Rancher
Posts: 1965
15
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I said before, you need some date functions here.  There are many methods like after, before , compareTo in date, you may look into those methods.
 
Campbell Ritchie
Marshal
Posts: 65102
247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is something not right about your line 11. Why are you storing a date as a String? If you are using a date picker, why is it returning a String? Which date picker are you using? Why are you not making the SQL do the comparisons? SQL is optimised for that sort of thing.

Which date class are you using? If Date/Calendar, can you change to the new Java8 date classes?
 
Rifa Ahmed
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now I am getting totally confused. Will you please check my whole code and suggest me what I have to do please? And is this necessary to define the date in the database? Suppose I am a departmental store's Admin. I get a delivery of a product and the date written of the packet of the product is like 1990-01-01. So when I enter this product with this date into my system,the system will give me a message that I can't Add this product and can't store this product. That's what I want.
Here is my code,


Sorry for this kind of newbie type question. I am totally at my learning stage and trying to implement whatever I am learning. :-/
 
Saloon Keeper
Posts: 10428
223
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The first thing you need to do is to model your stock. Right now all your logic is in your presentation layer (your GUI), which is BAD.

You need to separate your application into parts that handle the logic, such as adding expiration dates to products, parts that display your model in a GUI, and parts that know how to store and retrieve your model from a database.

For your model, use the new java.time package for dates and times. These can easily be converted to dates and times that databases understand.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!