我在SQL Server 2008中创建了以下存储过程

Create PROCEDURE countInfected @infected int out
AS
Select @infected = COUNT(*) from userInfo where userID NOT IN (Select userID from deletedInfo);


我的java代码如下

CallableStatement infected = con.prepareCall("exec countInfected()");
infected.registerOutParameter(1, java.sql.Types.INTEGER);
infected.execute();
    System.out.println("Infected"+ infected.getInt(1));


但是会产生以下错误


  core.dtable.Dbase.stored(Dbase.java:51)处的java.lang.NullPointerException


请指导我哪里我错了

最佳答案

     try {
        conn     = DBConnection.SQLDB();
        conn.setAutoCommit(false) ;
        CallableStatement cs = null;
        cs = conn.prepareCall("{call dbo.xxCount(?)}");
        cs.registerOutParameter(1, java.sql.Types.INTEGER);
        cs.execute() ;
        System.out.println("INFECTED "+cs.getInt(1));
    }catch (Exception err){


在对存储过程的调用中放入参数。

10-06 02:37