Skip to content
Advertisement

Date conversion format Java to DB different format

I’m making a code in java that executes an Oracle database procedure The format I have to put there in the procedure when I run through the database is dd/MM/yyyy. I have to send this date from my java code using a CallebleStatement setDate with the date yyyy-MM-dd (which is the Date format in java) When this CallebleStatement is executed, will it transform the date I’m sending to the database format, or will it write to the Java format?

EDIT: It is basically this:

if(types[1].compareTo("DATE") == 0) {//procedureValues[i] = yyyy-MM-dd HH:mm:ss
    cs.setDate(i+1, Date.valueOf(procedureValues[i].trim()));
}else {
    cs.setObject(i+1, procedureValues[i].trim(), SQLTypes.valueOf(types[1]).getTypes());    
}

And yes, the procedure expects the DATE format

Advertisement

Answer

In Oracle, a DATE is a binary data type composed of 7 bytes (century, year-of-century, month, day, hour, minute and second). It ALWAYS has those components and it NEVER stores a format.

When this CallebleStatement is executed, will it transform the date I’m sending to the database format, or will it write to the Java format?

If you are using CallableStatement.setDate(), it will transform it to the binary values required by the database. It will NOT store it in an (easily) human readable format.

If you want to see how the database stores the value then you can use:

SELECT DUMP(your_date_column) FROM your_table;

When you read the value from the database then the client application (in this case, Java via the database driver) will read the binary values from the database and will convert it to a representation suitable to the client application.

If you read it in a different client application then the binary values will be converted to the appropriate representation for that client application; so two different client applications (for example, Java and SQL/Plus) may display the same binary date value with different formats.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement