开发者

DateTime parameter when calling stored function from java code

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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜