这个问题出现有几天了,先详细描述一下现在的情况。
java实现了一个报表系统,其中有张日报表,所用的数据来源于一个存储过程处理之后的结果。存储过程如下:USE [mrsdb]
GO
/****** 对象:  StoredProcedure [dbo].[NEW_P_BRANCH_DAY]    脚本日期: 07/19/2011 09:12:27 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GOALTER PROCEDURE [dbo].[NEW_P_BRANCH_DAY] 
    @DT VARCHAR(8),
    @INST_CODE VARCHAR(11),
    @RESULT INT OUTPUT
AS 
SET @RESULT = 0
BEGIN TRY
BEGIN TRANSACTION

DELETE NEW_REP_BRANCH_DAY WHERE INST_CODE = @INST_CODE AND CLEAR_DATE = @DT


    INSERT INTO NEW_REP_BRANCH_DAY(
INST_CODE,MERCH_ID,MERCH_NAME,TRADE_COUNT,TRADE_AMOUNT,SHOUXU_FEE,TRADE_JING_AMOUNT,
KAIHU_BANK_NAME,KAIHU_MERCH_NAME,PAN,JIESUAN_BANK,FLAG,CLEAR_DATE

select distinct @INST_CODE, kk.merchid, 
kk.merchname,
kk.tradecount,
kk.tradeamount,
kk.shouxufee,
kk.tradejingamount,
kk.kaihubankname,
kk.kaihumerchname,
kk.pan,
kk.jiesuanbank,
kk.flag,
kk.cleardate
from (
select a.merch_id as merchid,
c.MERCH_NAME_CN_EX as merchname,
c_count+d_count as tradecount,
c_amount-d_amount as tradeamount,
fee_c_amt-fee_d_amt as shouxufee,
set_c_amt-set_d_amt as tradejingamount,
      case  when a.feature='1' and b.debit_card_acct_type='0' then f.sa_rsv_data8
            when a.feature='1' and b.debit_card_acct_type='1' then f.sa_rsv_data7
    when a.feature='2' and b.credit_card_acct_type='0' then f.sa_rsv_data8
when a.feature='2' and b.credit_card_acct_type='1' then f.sa_rsv_data7
when a.feature='3' and b.semi_credit_card_acct_type='0' then f.sa_rsv_data8
when a.feature='3' and b.semi_credit_card_acct_type='1' then f.sa_rsv_data7
when a.feature='4' and b.prepaid_card_acct_type='0' then f.sa_rsv_data8
when a.feature='4' and b.prepaid_card_acct_type='1' then f.sa_rsv_data7
      end as kaihubankname,
      
      case when a.feature='1' and b.debit_card_acct_type='0' then c.settle_acc_name2
            when a.feature='1' and b.debit_card_acct_type='1' then c.settle_acc_name
    when a.feature='2' and b.credit_card_acct_type='0' then c.settle_acc_name2
when a.feature='2' and b.credit_card_acct_type='1' then c.settle_acc_name
when a.feature='3' and b.semi_credit_card_acct_type='0' then c.settle_acc_name2
when a.feature='3' and b.semi_credit_card_acct_type='1' then c.settle_acc_name
when a.feature='4' and b.prepaid_card_acct_type='0' then c.settle_acc_name2
when a.feature='4' and b.prepaid_card_acct_type='1' then c.settle_acc_name
end as kaihumerchname,case when a.feature='1' then b.debit_card_acct
     when a.feature='2' then b.credit_card_acct 
     when a.feature='3' then b.semi_credit_card_acct 
     when a.feature='4' then b.prepaid_card_acct
end as pan,
case when b.debit_card_flag='0' then c.settle_bank2
     when b.debit_card_flag='1' then c.settle_bank end as jiesuanbank,
a.flag as flag,
a.clear_date as cleardate 
from t_merch_sum_zrrxyt_feature a 
left join tbl_merch_account b 
          on a.merch_id=b.merch_id 
left join t_merch c
          on a.merch_id=c.merch_id
left join (select distinct d.merch_id,e.branch_name,d.sa_rsv_data8,d.sa_rsv_data7
           from t_merch_etd d ,tbl_branch_inf e 
           where d.I_CLEAR_BRANCH_INDEX=e.id) as f
          on a.merch_id=f.merch_id
left join (select distinct i.merch_id,g.branch_name
           from t_merch_etd i ,tbl_branch_inf g 
           where i.I_MNG_BRANCH_INDEX =g.id) as h
          on a.merch_id=h.merch_id) as kk where kk.cleardate = @DT            UPDATE NEW_REP_BRANCH_DAY SET 
NEW_REP_BRANCH_DAY.INST_CODE_2 = (REP_MERCH_BRANCH_REL.INST_CODE_1),
NEW_REP_BRANCH_DAY.INST_CODE_3 = (REP_MERCH_BRANCH_REL.INST_CODE_2),
NEW_REP_BRANCH_DAY.INST_CODE_4 = (REP_MERCH_BRANCH_REL.INST_CODE_3),
NEW_REP_BRANCH_DAY.INST_CODE_5 = (REP_MERCH_BRANCH_REL.INST_CODE_4)
FROM REP_MERCH_BRANCH_REL
WHERE NEW_REP_BRANCH_DAY.CLEAR_DATE = @DT AND NEW_REP_BRANCH_DAY.INST_CODE = @INST_CODE AND NEW_REP_BRANCH_DAY.MERCH_ID = REP_MERCH_BRANCH_REL.MERCH_ID IF(@@ERROR <> 0)
    BEGIN
     ROLLBACK TRANSACTION   
        END
    ELSE 
        BEGIN
COMMIT TRANSACTION
END
END TRY
BEGIN CATCH
SET @RESULT = -1
END CATCH
这个存储过程每天执行一次,首先会把日期为当天的数据清除,再筛选数据插入NEW_REP_BRANCH_DAY这张表中。然后生成周报表时就直接从这张表中筛选一周的数据去处理,现在的问题是,每次跑完整个程序,在SQL Sever活动监视器中这个程序的进程状态为睡眠,但打开的事物为1,应用程序为空,等待时间为0,CPU为3249147,物理IO为36682,内存为2,TCP/IP,阻塞者0,阻塞1.该报表系统的程序是Timer实现的定时任务,每天固定时间执行一次,每天跑完之后程序不会关闭,等待下一次运行。现在程序每天跑完之后,生成的日报表是正确的,也就是说从NEW_REP_BRANCH_DAY取到了存储过程筛选之后得到的当天的数据,但是我想去查询这张表中的数据时,Select * from NEW_REP_BRANCH_DAY 这个语句就一直被挂起,应该是这张表被锁住了。之前为了成功执行Select * from NEW_REP_BRANCH_DAY去验证当天的数据有没有被存进该表,我就把报表系统程序关了,关了之后是能执行Select * from NEW_REP_BRANCH_DAY了,但是却没有当天的数据。 这样在生成周报表时,就会因为没有那天的数据造成报表中数据不对。之后我发现更诡异的事,就是如果我一直让报表程序运行,第一天跑完之后会卡住这个事务,NEW_REP_BRANCH_DAY表也是被锁住的,第二天跑完也是这个状态,但是当我在第三天跑完之后把报表程序关闭,执行Select * from NEW_REP_BRANCH_DAY会发现第一天和第二天的数据都被插入到表中,但第三天的数据却丢失了。问题详细描述就是这么多了,请各位大大帮帮忙,指教下是这是什么情况在java代码或者存储过程中造成这种现在的原因可能有哪些。 还有要说的一点就是java代码中的数据库连接模块是封装好的,有开就有关,存在数据库链接一直或者的可能。