我正在尝试从Java中的过程中检索结果集,但我无法这样做。虽然这次我通常很容易检索结果集,但是遇到空指针异常。
这是我的sql server 2008版本:
ALTER PROCEDURE [dbo].[SSSMLTransaction]
@acid int,@subacid int
AS
BEGIN
CREATE TABLE trans ( Vtype varchar(10),Vno varchar(5),Vdate date,Narr varchar(50),dr numeric(13,2),cr numeric(13,2),DCIND varchar(1));
insert into trans(Vtype,Vno,Vdate,Narr,dr,cr,DCIND)
(select 'Cash',cd.V_no,cv.VDate,cv.Narr1,cd.Debit,cd.Credit,cd.DCIND from CVDetail cd join CashVoucher cv on cd.V_no=cv.Vno where
cd.ANO=@acid and cd.Party_Code=@subacid) ;
select * from trans;
drop table trans;
END
这是我的Java函数:
CallableStatement cs = conn.prepareCall("{call SSSMLTransaction(?,?)}");
cs.setInt(1, acid);
cs.setInt(2, prtyid);
cs.execute();
rs=cs.getResultSet();
但是我得到了一个空的结果集。
答案 0 :(得分:0)
尝试:
ResultSet rs = cs.executeQuery();
答案 1 :(得分:0)
从Procedure中检索数据的最佳方法如下:
public static void executeProcedure(Connection con) {
try {
CallableStatement stmt = con.prepareCall(...);
..... //Set call parameters, if you have IN,OUT, or IN/OUT parameters
boolean results = stmt.execute();
int rsCount = 0;
//Loop through the available result sets.
while (results) {
ResultSet rs = stmt.getResultSet();
//Retrieve data from the result set.
while (rs.next()) {
....// using rs.getxxx() method to retieve data
}
rs.close();
//Check for next result set
results = stmt.getMoreResults();
}
stmt.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
在您的情况下,我认为没有数据可以根据您的SQL查询返回。