File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes A challenge while formatting date value from the database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "A challenge while formatting date value from the database" Watch "A challenge while formatting date value from the database" New topic
Author

A challenge while formatting date value from the database

ramya narayanan
Ranch Hand

Joined: Oct 06, 2008
Posts: 338
Dear All,
I'm fetching a set of data from the database which includes some date values.
This is my code:

When we run:

Now I want to format the date in dd/MM/yyyy format for which I use SimpleDateFormat class

My code now:

But now the output is:


It's not displaying other datas, once it encounters the first null value in date.
But when we don't use formatting, these null values are also getting displayed.
Now, my requirement is
1) I want to display the date value in a formatted manner
2) If atall some null date values are there it should be presented as null.
I want the output to be in this format.

sai : 11850 : 26/09/2006
azees : 11851 : null
jothish : 11856 : null
pradap : 11859 : 12/12/2006


How can i achieve this?
Regards.
ramya narayanan
Ranch Hand

Joined: Oct 06, 2008
Posts: 338
The challenge is won now , by including a simple if statement after fetching the date value & checking for null value.
Note the whole output is formatted using String.format method which is highlighted.
Code:


Output:


Regards.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: A challenge while formatting date value from the database
 
Similar Threads
Closing a db connection
ORA-12514: TNS:listener could not resolve SERVICE_NAME given?
Create JTable custom editor to validate againts string data type
MySQLException
accessdata using excel