• Post Reply Bookmark Topic Watch Topic
  • New Topic

How do I make my table from JDBC SQL that displays Date as YY/MM/dd display as MM/dd/YY?  RSS feed

 
Tim Rawley
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I'm still very very new to Java, JDBC, Tables, and SQL.
The short explanation is I've written a program that stores serial keys and can email the owner when the key is about to expire.  The date is stored in SQL as a Date

We have been using it for a few months now and it seems to be working OK, but my boss asked me to change the way the dates are displayed because is hard to read.
I would like it to be MM/dd/YYYY on the Tables, and also when I getValueAt(rows, columns).toString() to save to a file.



I'm not sure what to change  resultset, table, SQL query or maybe use SimpleDateFormat.

The more I read the more confused I get.

Thanks for the help.

 
Tapas Chand
Ranch Hand
Posts: 614
9
BSD Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No need to change anything in table. Let it store as "date" datatype.
While executing SELECT query, date can be formatted as how you want to display it.
Different databases have different syntax for formatting. Which database are you using?
 
Tim Rawley
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
at work I'm using mySQL from windows and at home I have hyper-v running turnkey lamp and I guess it is also mySQL    Same??
 
Dave Tolls
Ranch Foreman
Posts: 3068
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where is the date being displayed that needs to be formatted?
If it's in Java then retrieve the DATE as a Date object and then use SimpleDateFormat at the point you want to display it.

I presume you have a model that represents whatever data this is, so that model will currently have a Date member that represents this column.
It seems to me this is all about display, so forget about the DB and concentrate on wherever it is being displayed.
 
Tim Rawley
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


select * ,DATE_FORMAT(dateexp, '%b-%d-%Y') as Expires from vipreserial

now it shows up as   Expires: Oct-19-2017
then I made the expires column 0
I was able the leave the rest of the code the same
thanks for the help.
 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well done finding that format instruction
 
Dave Tolls
Ranch Foreman
Posts: 3068
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nice that it was that simple, but that implies your Java code is representing Dates as Strings...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!