Reputation: 21901
I am trying to insert date and time but only the date goes through. when I check the database the time is always 00:00
public void suspendPart(String partId, String startDate,
String reasonCode, String endDate) throws DAOException {
System.out.println("original date: "+startDate); //output: original date: 04/01/2013 08:42
SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm");
Map<String, Object> params = new HashMap<String, Object>();
params.put("p_id", Integer.parseInt(partId));
Date dateTest = DAOUtils.parseDate(startDate, format);
System.out.println("date after format " +dateTest); // output: date after format Fri Jan 04 08:42:00 GMT 2013
params.put("p_start_date", dateTest);
parts_package_add_part.execute(params);
}
I managed to make it work once but I don't know how. by the time I checked the database and saw a row with proper time, I had already messed with the code so it was lost.
Can anyone see what I'm doing wrong?
Edit: sp declaration
parts_package_add_part = SpringStoredProcedure
.getStoredProcedureCompiled(getJdbcTemplate(), false,
"parts_package.add_part",
new SqlParameter("part_id", OracleTypes.NUMBER),
new SqlParameter("p_start_date", OracleTypes.DATE));
Edit: I can't change the database. well not easily at least. I would need to get PLSQL developer to do it and that will take days
Upvotes: 1
Views: 470
Reputation: 483
Hi try using timestamp datatype in your database table and also from your java code use java.sql.Timestamp it will store data and time both for you Thanks
Upvotes: 1
Reputation: 23
Using Timestamp could help. What is the datatype used to store your date in db? May be it is a Date type. If you convert that to Timestame/DateTime it could help.
Upvotes: 2
Reputation: 1710
I recently had a simular problem. My solution was to use TIMESTAMP as oracle data type in the database table and the java.sql.Timestamp class in java. This matched fine...
Upvotes: 2