从java代码调用存储函数时的DateTime参数
我用这样的签名调用存储的函数:
函数添加日期(城市 VARCHAR2, 开始日期 DATE,numDays INTEGER)
来自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());
}
});
:当我传递startDate时,时间返回值包含00:00作为时间(存储过程不会削减时间部分,我通过sql编辑器的直接调用检查它)。 所以看起来时间部分在发送到/接收 Oracle 时被删除了。 可以修复吗? 谢谢。
I call stored function with such signature:
FUNCTION ADDDAYS (city VARCHAR2,
startDate DATE, numDays INTEGER)
from java code:
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
java.sql.Date
旨在仅存储日期而不存储时间信息。您应该使用 java.sql.Timestamp、setTimestamp 和 getTimestamp 来处理日期和时间。时间信息。
如果您只需要时间信息,另请参阅
java.sql.Time
和set/getTime
。java.sql.Date
is meant to store only date without time information.You should use
java.sql.Timestamp
,setTimestamp
andgetTimestamp
to handle date & time informations.Look also at
java.sql.Time
andset/getTime
if you need only time information.