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
CodePudding user response:
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.
CodePudding user response:
If the Date format in Java you're using is not compatible with the Date format of your database, the procedure will fail, because the procedure takes a String of dd/mm/yyyy and not a date instance.
You'll have to make sure your Java Date type is the correct from or transform it to match Oracle Date type dd/mm/yyyy and then use it as an argument in the procedure.
An easy and simple solution is to use a String instead of a Date type in Java and use that String as an argument to the procedure, but that depends on your input and program
