My application is using an Oracle database and one of the table contains a date column. When doing my queries inside SQLDeveloper I need to add the following line to get the date + hours
alter session set nls_date_format = 'DD/MM/YYYY HH24:MI:SS';
If I do not use this, I only see the date like 25/11/2016
When I am doing my queries from my JAVA code I don't have the above line thus every date is returned in the format DD/MM/YY
JAVA
String query = "SELECT date from SCHEMA.table";
ResultSet rs = null;
try {
connection = ConnectionFactory.getConnection(Database.ORACLE);
preparedStatement = connection.prepareStatement(query);
rs = preparedStatement.executeQuery();
while (rs.next()) {
java.sql.Date dateDB = rs.getDate("date");
}
catch(SQLException e){
//error
}
How can I get the date with the hours ? Should I add alter session ...
to each query ?