oracle 从java代码调用存储函数时的DateTime参数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2643789/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
DateTime parameter when calling stored function from java code
提问by dbf
I call stored function with such signature:
我用这样的签名调用存储函数:
FUNCTION ADDDAYS (city VARCHAR2, startDate DATE, numDays INTEGER)
FUNCTION ADDDAYS (city VARCHAR2, startDate DATE, numDays INTEGER)
from java code:
来自java代码:
JdbcTemplate jt = getJdbcTemplate();
Object o = jt.execute("{? = call ADDDAYS(?, ?, ?)}", new CallableStatementCallback() {
public Object doInCallableStatement(CallableStatement stmt) throws SQLException, DataAccessException {
stmt.registerOutParameter(1, Types.DATE);
stmt.setString(2, city);
stmt.setDate(3, new java.sql.Date(startDate.getTime()));
stmt.setInt(4, daysNum);
stmt.execute();
return new Date(stmt.getDate(1).getTime());
}
});
when I pass startDate with time return value contais 00:00 as time (stored procedure doesn't cut time part, i checked it with direct calls from sql editor). So looks like time part is removed in sending to/receiving form Oracle. is it possible to fix it? Thanks.
当我通过带有时间返回值包含 00:00 作为时间的 startDate 时(存储过程不会削减时间部分,我通过 sql 编辑器的直接调用进行了检查)。所以看起来时间部分在发送到/接收形式 Oracle 中被删除了。有没有可能修复它?谢谢。
回答by Andrea Polci
java.sql.Date
is meant to store only date without time information.
You should use java.sql.Timestamp
, setTimestamp
and getTimestamp
to handle date & time informations.
Look also at java.sql.Time
and set/getTime
if you need only time information.
java.sql.Date
旨在仅存储没有时间信息的日期。您应该使用java.sql.Timestamp
,setTimestamp
和getTimestamp
来处理日期和时间信息。还看java.sql.Time
和set/getTime
,如果你只需要时间信息。