How to Format Dates Between Java and Oracle
Oracle database systems and the Java programming language are commonly used in tandem. Java-based applications and scripts can be written to log in to Oracle database servers and administer changes and perform queries on data stored in the database. Software engineers use Java to create applications that allow users to interact with large amounts of information. A common attribute, such as a date, can be stored in one format in the Oracle database, but may need to be displayed and formatted another way in the Java application.
Instructions
-
-
1
Open the Java code that you need to modify using your preferred code editing application or a plain text editor such as Windows' NotePad or Mac OS X's TextEdit.
-
2
Navigate to the section of code responsible for passing the date between the Java application and the Oracle database.
-
-
3
Select the database and date field that you need to format. Use this code as a guide and replace the example database name with the one you need to use:
select * from example_database
select * lastlogin_date_example -
4
Format the date in Java by adding this final line of code after the database querying code in Step 3. Change the date format to the format you wish to use:
select to _char (sysdate, 'MON-DD-RRRR HH12:MI:SS')
-
5
Save the changes to your Java application and test the formatting before deploying the code changes to the application's production environment where it will be used by end users.
-
1