• Post Reply Bookmark Topic Watch Topic
  • New Topic

String to date problem  RSS feed

 
Tim Nachreiner
Ranch Hand
Posts: 61
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have this class:



I can't figure out how to stuff a date from a JTextfield into this element.



How to I convert date to a date compatible with java.sql.Date?
The larger question is whether passwordChangeDate has the correct data type. Maybe it should have been java.util.Date? I am storing this info in a database. What is the standard way of datatyping date elements that are stored in a database?

 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you have an object of one class (call it "A") and you need an object of a different class ("B")? Then you need to look at the ways that exist to create a B object, and then see what you might do with your A object to provide the information needed. (This technique is of general use, not just with dates, hence "A" and "B".)

In the simplest case, java.sql.Date would have a constructor that takes a java.util.Date as an arg. It doesn't however (and I have no idea why not--seems like a stupid design choice to me), but it does have another constructor that you can use.

And Welcome to the Ranch!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!