Problems with the passing date parameter of Java calling stored procedures

Source: Internet
Author: User
Tags datetime sybase

A stored procedure was built

create procedure PR_YDFT_GETFT_TIME
 @AJLB   tinyint,      -- 案件类别
 @AJBHLIST varchar(1500),   -- 案件编号列表
 @KSSJ   datetime,      -- 开始时间
 @JSSJ   datetime      -- 结束时间
as
begin
…………
select BH, AH from K_ZS..B_ZX where(这里返回一个结果集)
end

The following call in Java code (the time type is java.sql.Date) does not return the result set correctly, even if the database has data:

public Object doInCallableStatement(CallableStatement cs) throws SQLException, DataAccessException {
   //………………
   cs.setDate(3, new java.sql.Date(kssj.getTime()));
   cs.setDate(4, new java.sql.Date(jssj.getTime()));
   //………………
}

Instead, you can return the result set normally by changing the method as follows (the time type is string):

public Object doInCallableStatement(CallableStatement cs) throws SQLException, DataAccessException {
  //………………
   cs.setString(3, kssj);
  cs.setString(4, jssj);
  //………………
 }

In Sybase's SQLADV, the following two modes of invocation can return the result correctly:

use K_RW
go
PR_YDFT_GETFT_TIME 2, "109052298;", "2008-08-19 14:00:00", "2008-08-19 17:00:00"
use K_RW
go
declare @KSSJ datetime
declare @JSSJ datetime
select @KSSJ = convert(datetime,"2008-08-19 14:00:00")
select @JSSJ = convert(datetime,"2008-08-19 17:00:00")
execute PR_YDFT_GETFT_TIME 2, "109052298;", @KSSJ ,@JSSJ

Does calling in Java code simply change the java.sql.Date parameter type to string to return the result set correctly because Sybase has a problem with the driver?

The reason for the problem was found because using cs.setdate () to pass parameters to the database will only be the date part.

If you use the following code instead:

cs.setTimestamp(3, new java.sql.Timestamp(dKssj.getTime()));
cs.setTimestamp(4, new java.sql.Timestamp(dJssj.getTime()));
cs.setTimestamp()可以将日期和时间部分都传给数据库。

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.