SQL JDBC upgrade from v6.0 to v7.2 causes java.lang.NullPointerException in some stored procedure...

How can I portray body horror and still be sensitive to people with disabilities?

Why is Shelob considered evil?

What does "don't have a baby" imply or mean in this sentence?

Given the mapping a = 1, b = 2, ... z = 26, and an encoded message, count the number of ways it can be decoded

SQL Server 2017 crashes when backing up because filepath is wrong

How to achieve physical gender equality?

Coworker asking me to not bring cakes due to self control issue. What should I do?

How to play songs that contain one guitar when we have two or more guitarists?

What does @ mean in a hostname in DNS configuration?

How can I make my enemies feel real and make combat more engaging?

How do I avoid the "chosen hero" feeling?

Why are `&array` and `array` pointing to the same address?

What is the reason behind this musical reference to Pinocchio in the Close Encounters main theme?

Can a planet be tidally unlocked?

Now...where was I?

Is it common to refer to someone as "Prof. Dr. [LastName]"?

Buying a "Used" Router

TikZtree with asymmetric siblings

Why are "square law" devices important?

How Create a list of the first 10,000 digits of Pi and sum it?

Is layered encryption more secure than long passwords?

Badly designed reimbursement form. What does that say about the company?

Is there a way to pause a running process on Linux systems and resume later?

Cryptic cross... with words



SQL JDBC upgrade from v6.0 to v7.2 causes java.lang.NullPointerException in some stored procedure returned


Does it make sense to upgrade to a newer PostgreSQL JDBC driver?Install JDBC driver 4.0 for SQL ServerJDBC connection error for SQL Server DatabaseMySQL overhead of calling a Stored ProcedureDimension design and MDX query issueJDBC Statement vs. Prepared Statement SQL InjectionSQL Server stored procedure namingDisallowing MariaDB query cache except from webserver (JDBC)How properly call stored procedure from EXEC(SQL)?Error with SQL stored procedure output type













0















I am developing a java application onWindows 10 using Eclipse Oxygen and SQL JDBC v7.2 and java 1.8 update 202. My code runs fine when I use SQL JDBC v6.0 (sqljdbc42.jar Jan 2017 and java 8), but gives the same java.lang.NullPointerException with SQL JDBC v7.2 (mssql-jdbc-7.2.1.jre8.jar with java 8u202) or (mssql-jdbc-7.2.1.jre11.jar with java 11.0.2) at line rs.next() or any command that attempts to access the recordset (rs) because the recordset value is null.



(We need to upgrade to v7.2 to be compatible with java 11 as soon as possible. I have many stored procedures that run fine and two stored procedures that cause this java.lang.NullPointerException error for one recordset in their results. I am only including the code for one here.)



Here is my attempt to fulfill Guidelines when posting JDBC related questions:
[1] Client side:
1. Which OS platform are you running on? [SQL Server 2012 on Windows 2012 with dev. client Windows 10 with java 8u202)
2. Which JVM are you running on? java 8 update 202 (trying to eventually update to java 11.0.2)
3. What is the connection URL in you app? Rather not share; connection not an issue.
4. If client fails to connect, what is the client error messages? N/A, connects fine.
5. Is the client remote or local to the SQL server machine? Remote
6. Is your client computer in the same domain as the Server computer? (Same domain)
[2] Server side:
1. What is the MS SQL version? [ SQL Server 2012]
2. Does the server start successfully? [YES]
3. If SQL Server is a named instance, is the SQL browser enabled? [YES]
4. What is the account that the SQL Server is running under?[Domain Account]
5. Do you make firewall exception for your SQL server TCP port if you want connect remotely through TCP provider? [YES]
6. Do you make firewall exception for SQL Browser UDP port 1434? In SQL2000, you still need to make firewall exception for UDP port 1434 in order to support named instance.[not applicable]



Tips:
1. If you are executing a complex statement query or stored procedure, please use execute() instead of executeQuery(). [Yes, I use .execute() to execute the CallableStatement that calls the stored procedure in the database.]
2. If you are using JDBC transactions, do not mix them with T-SQL transactions. [No we are not using transactions. Simple calls to stored procedures that return combination of output parameters and recordsets. We process the recordset information before retrieving output parameters.]



Database connection works fine and output variables and some recordsets return valid results and work fine.



The attached stored procedure gives error with JDBC v7.2 when using original complex query for the recordset; it has run fine for years with JDBC v6.0.



Deploying static tables of the same data works fine in JDBC 7.2.

Java code:
// Create database connection and statement
Connection con = null;



    // Establish the connection.
SQLServerDataSource ds = new SQLServerDataSource();
ds.setUser(strDatabaseUser);
ds.setPassword(strDatabasePassword);
ds.setServerName(strDatabaseServerName);
ds.setPortNumber(intDatabaseServerPort);
ds.setDatabaseName(strDatabaseName);

try {
con = ds.getConnection();
}
catch (SQLException se) {
do {
System.out.println("SQL STATE: " + se.getSQLState());
System.out.println("ERROR CODE: " + se.getErrorCode());
System.out.println("MESSAGE: " + se.getMessage());
System.out.println();
se = se.getNextException();
} while (se != null);
}

CallableStatement cstmt2 = null;

if (intArchiveID == -1)
cstmt2 = con.prepareCall("{call dbo.selProjectTractFunding(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}");
else
{
cstmt2 = con.prepareCall("{call dbo.selProjectTractFundingFromArchive(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}");
cstmt2.setInt("ArchiveID",intArchiveID);
}
cstmt2.setInt("ProjectID",intProjectID);
cstmt2.setInt("CurrentProposedFundingFY", intCurrentProposedFundingFY);
cstmt2.registerOutParameter("LastStatusCD", java.sql.Types.INTEGER);
cstmt2.registerOutParameter("LastFundingFY", java.sql.Types.INTEGER);
cstmt2.registerOutParameter("curFundingAmount", java.sql.Types.INTEGER);
cstmt2.registerOutParameter("curCostShareAmount", java.sql.Types.INTEGER);
cstmt2.registerOutParameter("curTotalFLPCost", java.sql.Types.INTEGER);
cstmt2.registerOutParameter("curOtherFedAmount", java.sql.Types.INTEGER);
cstmt2.registerOutParameter("curOtherFedCostShareAmount", java.sql.Types.INTEGER);
cstmt2.registerOutParameter("curTotalCost", java.sql.Types.INTEGER);
cstmt2.registerOutParameter("curAcre", java.sql.Types.INTEGER);
cstmt2.registerOutParameter("TotalFundingAmount", java.sql.Types.INTEGER);
cstmt2.registerOutParameter("TotalCostShareAmount", java.sql.Types.INTEGER);
cstmt2.registerOutParameter("TotalFLPCost", java.sql.Types.INTEGER);
cstmt2.registerOutParameter("TotalOtherFedAmount", java.sql.Types.INTEGER);
cstmt2.registerOutParameter("TotalOtherFedCostShareAmount", java.sql.Types.INTEGER);
cstmt2.registerOutParameter("TotalCost", java.sql.Types.INTEGER);
cstmt2.registerOutParameter("TotalAcre", java.sql.Types.INTEGER);
cstmt2.registerOutParameter("FundingAmountToDate", java.sql.Types.INTEGER);

boolean bCstmt2Exe = cstmt2.execute();
ResultSet rs2=null;
//if (bCstmt2Exe == true)
rs2 = cstmt2.getResultSet();


Table tblTracts = new Table(new float[]{ 6,3,5,5,5,5 });
tblTracts.setWidth(468f);
tblTracts.setMarginBottom(12f);
tblTracts.getAccessibilityProperties().addAttributes(new PdfStructureAttributes("Table").addTextAttribute("Summary","This table lists all tracts in the project and their size, cost, FLP funding, Cost Share and Status." ));

float fltCellPaddingTop=0f;
float fltCellPaddingRight=2f;
float fltCellPaddingLeft=2f;
float fltCellPaddingBottom=-1f;

Cell c1 = new Cell().add(new Paragraph("Tract Name")).addStyle(styleTableHeader);
c1.setTextAlignment(TextAlignment.LEFT);
c1.setVerticalAlignment(VerticalAlignment.BOTTOM);
c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
tblTracts.addHeaderCell(c1);

c1 = new Cell().add(new Paragraph("Size (ac)")).addStyle(styleTableHeader);
c1.setTextAlignment(TextAlignment.CENTER);
c1.setVerticalAlignment(VerticalAlignment.BOTTOM);
c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
tblTracts.addHeaderCell(c1);

c1 = new Cell().add(new Paragraph("Tract Cost")).addStyle(styleTableHeader);
c1.setTextAlignment(TextAlignment.CENTER);
c1.setVerticalAlignment(VerticalAlignment.BOTTOM);
c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
tblTracts.addHeaderCell(c1);

c1 = new Cell().add(new Paragraph("FLP Funding")).addStyle(styleTableHeader);
c1.setTextAlignment(TextAlignment.CENTER);
c1.setVerticalAlignment(VerticalAlignment.BOTTOM);
c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
tblTracts.addHeaderCell(c1);

c1 = new Cell().add(new Paragraph("Non-Fed Cost Share")).addStyle(styleTableHeader);
c1.setTextAlignment(TextAlignment.CENTER);
c1.setVerticalAlignment(VerticalAlignment.BOTTOM);
c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
tblTracts.addHeaderCell(c1);

c1 = new Cell().add(new Paragraph("Status")).addStyle(styleTableHeader);
c1.setTextAlignment(TextAlignment.CENTER);
c1.setVerticalAlignment(VerticalAlignment.BOTTOM);
c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
tblTracts.addHeaderCell(c1);


while (rs2.next()){
int intTractID = rs2.getInt("TractID");
logger.info("nTractID: "+
Integer.toString(intTractID));

c1 = new Cell().add(new Paragraph(rs2.getString("TractName")).addStyle(styleTableCell));
c1.setTextAlignment(TextAlignment.LEFT);
c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
tblTracts.addCell(c1);
c1 = new Cell().add(new Paragraph(integerFormatter.format(rs2.getInt("Acre"))).addStyle(styleTableCell));
c1.setTextAlignment(TextAlignment.RIGHT);
c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
tblTracts.addCell(c1);
c1 = new Cell().add(new Paragraph(currencyFormatter.format(rs2.getInt("FLPCost"))).addStyle(styleTableCell));
c1.setTextAlignment(TextAlignment.RIGHT);
c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
tblTracts.addCell(c1);
c1 = new Cell().add(new Paragraph(currencyFormatter.format(rs2.getInt("FundingAmount"))).addStyle(styleTableCell));
c1.setTextAlignment(TextAlignment.RIGHT);
c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
tblTracts.addCell(c1);
c1 = new Cell().add(new Paragraph(currencyFormatter.format(rs2.getInt("CostShareAmount"))).addStyle(styleTableCell));
c1.setTextAlignment(TextAlignment.RIGHT);
c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
tblTracts.addCell(c1);
c1 = new Cell().add(new Paragraph(rs2.getString("DisplayStatusFY")).addStyle(styleTableCell));
c1.setTextAlignment(TextAlignment.CENTER);
c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
tblTracts.addCell(c1);
}


int LastFundingFY = cstmt2.getInt("LastFundingFY");
int curFundingAmount = cstmt2.getInt("curFundingAmount");
int curCostShareAmount = cstmt2.getInt("curCostShareAmount");
int curTotalFLPCost = cstmt2.getInt("curTotalFLPCost");
int curAcre = cstmt2.getInt("curAcre");
int TotalFLPCost = cstmt2.getInt("TotalFLPCost");
int TotalAcre = cstmt2.getInt("TotalAcre");
int FundingAmountToDate = cstmt2.getInt("FundingAmountToDate");

Table tblFunding = new Table(new float[]{120,60});
float fltTableFundingCellHeight = 12f;
tblFunding.setWidth(270F);
tblFunding.setMarginBottom(16f);
tblFunding.getAccessibilityProperties().addAttributes(new PdfStructureAttributes("Table").addTextAttribute("Summary","This table provides an overview of the Forest Legacy Program funding history for this project." ));

c1 = new Cell().add(new Paragraph("FY " + LastFundingFY + " Forest Legacy Program Funding").addStyle(styleTableHeader));
c1.setTextAlignment(TextAlignment.RIGHT);
c1.setBorder(Border.NO_BORDER);
c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
c1.setHeight(fltTableFundingCellHeight);
c1.getAccessibilityProperties().setRole(StandardRoles.TH);
tblFunding.addCell(c1);
c1 = new Cell().add(new Paragraph(currencyFormatter.format(curFundingAmount)).addStyle(styleTableHeader));
c1.setTextAlignment(TextAlignment.RIGHT);
c1.setBorder(Border.NO_BORDER);
c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
c1.setHeight(fltTableFundingCellHeight);
tblFunding.addCell(c1);

c1 = new Cell().add(new Paragraph("FY " + LastFundingFY + " Non-Federal Cost Share").addStyle(styleTableHeader));
c1.setTextAlignment(TextAlignment.RIGHT);
c1.setBorder(Border.NO_BORDER);
c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
c1.setHeight(fltTableFundingCellHeight);
c1.getAccessibilityProperties().setRole(StandardRoles.TH);
tblFunding.addCell(c1);
c1 = new Cell().add(new Paragraph(currencyFormatter.format(curCostShareAmount)).addStyle(styleTableHeader));
c1.setTextAlignment(TextAlignment.RIGHT);
c1.setBorder(Border.NO_BORDER);
c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
c1.setHeight(fltTableFundingCellHeight);
tblFunding.addCell(c1);

c1 = new Cell().add(new Paragraph("FY " + LastFundingFY + " Project Costs").addStyle(styleTableHeader));
c1.setTextAlignment(TextAlignment.RIGHT);
c1.setBorder(Border.NO_BORDER);
c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
c1.setHeight(fltTableFundingCellHeight);
c1.getAccessibilityProperties().setRole(StandardRoles.TH);
tblFunding.addCell(c1);
c1 = new Cell().add(new Paragraph(currencyFormatter.format(curTotalFLPCost)).addStyle(styleTableHeader));
c1.setTextAlignment(TextAlignment.RIGHT);
c1.setBorder(Border.NO_BORDER);
c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
c1.setHeight(fltTableFundingCellHeight);
tblFunding.addCell(c1);


c1 = new Cell().add(new Paragraph("FY " + LastFundingFY + " Project Acres").addStyle(styleTableHeader));
c1.setTextAlignment(TextAlignment.RIGHT);
c1.setBorder(Border.NO_BORDER);
c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom + 10f, fltCellPaddingLeft);
c1.setHeight(fltTableFundingCellHeight);
c1.getAccessibilityProperties().setRole(StandardRoles.TH);
tblFunding.addCell(c1);
c1 = new Cell().add(new Paragraph(integerFormatter.format(curAcre)).addStyle(styleTableHeader));
c1.setTextAlignment(TextAlignment.RIGHT);
c1.setBorder(Border.NO_BORDER);
c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom + 10f, fltCellPaddingLeft);
c1.setHeight(fltTableFundingCellHeight);
tblFunding.addCell(c1);

c1 = new Cell().add(new Paragraph("Forest Legacy Funding To Date").addStyle(styleTableHeader));
c1.setTextAlignment(TextAlignment.RIGHT);
c1.setBorder(Border.NO_BORDER);
c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
c1.setHeight(fltTableFundingCellHeight);
c1.getAccessibilityProperties().setRole(StandardRoles.TH);
tblFunding.addCell(c1);
c1 = new Cell().add(new Paragraph(currencyFormatter.format(FundingAmountToDate)).addStyle(styleTableHeader));
c1.setTextAlignment(TextAlignment.RIGHT);
c1.setBorder(Border.NO_BORDER);
c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
c1.setHeight(fltTableFundingCellHeight);
tblFunding.addCell(c1);

c1 = new Cell().add(new Paragraph("Total Project Costs").addStyle(styleTableHeader));
c1.setTextAlignment(TextAlignment.RIGHT);
c1.setBorder(Border.NO_BORDER);
c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
c1.setHeight(fltTableFundingCellHeight);
c1.getAccessibilityProperties().setRole(StandardRoles.TH);
tblFunding.addCell(c1);
c1 = new Cell().add(new Paragraph(currencyFormatter.format(TotalFLPCost)).addStyle(styleTableHeader));
c1.setTextAlignment(TextAlignment.RIGHT);
c1.setBorder(Border.NO_BORDER);
c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
c1.setHeight(fltTableFundingCellHeight);
tblFunding.addCell(c1);

c1 = new Cell().add(new Paragraph("Total Project Acres").addStyle(styleTableHeader));
c1.setTextAlignment(TextAlignment.RIGHT);
c1.setBorder(Border.NO_BORDER);
c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
c1.setHeight(fltTableFundingCellHeight);
c1.getAccessibilityProperties().setRole(StandardRoles.TH);
tblFunding.addCell(c1);
c1 = new Cell().add(new Paragraph(integerFormatter.format(TotalAcre)).addStyle(styleTableHeader));
c1.setTextAlignment(TextAlignment.RIGHT);
c1.setBorder(Border.NO_BORDER);
c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
c1.setHeight(fltTableFundingCellHeight);
tblFunding.addCell(c1);

cstmt2.close();


Here is the Stored Procedure that gives error. (Please note comment of sql query that if converted to static table, resolves the error!):



/****** Object: StoredProcedure [dbo].[selProjectTractFunding] Script Date: 2/20/2019 3:48:22 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
*/



CREATE PROCEDURE [dbo].[selProjectTractFunding] ( @ProjectID int,
@CurrentProposedFundingFY int, @LastStatusCD int out, @LastFundingFY int out,
@curFundingAmount int out, @curCostShareAmount int out,
@curTotalFLPCost int out, @curOtherFedAmount int out,
@curOtherFedCostShareAmount int out, @curTotalCost int out,
@curAcre int out, @TotalFundingAmount int out,
@TotalCostShareAmount int out, @TotalFLPCost int out,
@TotalOtherFedAmount int out, @TotalOtherFedCostShareAmount int out,
@TotalCost int out, @TotalAcre int out,
@FundingAmountToDate int out )
AS
declare @RC int



/***  All works FINE if I convert this first query to a static table TEMP1 and replace it with "select * from temp1".  Does not work from temporary table #temp1 as coded here.  ***/
select pt.ProjectID
,t.TractID
,t.TractName
,t.PurchaseTypeCD
,cast(isnull(t.Acre,0) as int) as Acre
,cast(isnull(t.FundingAmount,0) as bigint) as FundingAmount
,cast(isnull(costshare.CostShareAmount,0) as bigint) as CostShareAmount
,cast((isnull(t.FundingAmount,0) + isnull(costshare.CostShareAmount,0)) as bigint) as FLPCost
,cast(isnull(ofed.OtherFedAmount,0) as bigint) as OtherFedAmount
,cast(isnull(ofed.OtherFedCostShareAmount,0) as bigint) as OtherFedCostShareAmount
,cast((isnull(t.FundingAmount,0) + isnull(costshare.CostShareAmount,0) + isnull(ofed.OtherFedAmount,0) + isnull(ofed.OtherFedCostShareAmount,0)) as bigint) as TotalCost
,cast(dbo.getFY(CompleteDate) as int) as CompleteFY
,ts.StatusCD
,s.Status
,s.DisplayStatus
,cast(case when t.CompleteDate is null then s.DisplayStatus + ' ' + cast(ts.FundingFY as varchar) else s.DisplayStatus + ' ' + cast(dbo.getFY(t.CompleteDate) as varchar) end as varchar) as DisplayStatusFY
,ts.FundingFY
,ts.CreatedOn
into #temp1
from (select TractID, max(CreatedOn) as CreatedOn from dbo.TractStatus group by TractID ) cs
inner join dbo.TractStatus ts on cs.TractID = ts.TractID and cs.CreatedOn = ts.CreatedOn
inner join dbo.Tract t on ts.TractID = t.TractID
inner join dbo.ProjectTract pt on t.TractID = pt.TractID
left outer join (select TractID, Sum(OtherFedAmount) as OtherFedAmount, sum(OtherFedCostShareAmount) as OtherFedCostShareAmount from dbo.OtherFederal group by TractID ) ofed on ofed.TractID = t.TractID
left outer join (select TractID, sum(CostShareAmount) as CostShareAmount from dbo.CostShare group by TractID) costshare on costshare.TractID = t.TractID
inner join dbo._refStatus s on ts.StatusCD = s.StatusCD
where pt.ProjectID = @ProjectID
and ts.StatusCD <> 120

set @RC = @@RowCount

-- Return recorset of tract details
select * from #temp1 t
order by t.TractName

-- Get Last or Latest Status (other than closed/complete) for latest FundingFY for Project
select top 1 @LastStatusCD = StatusCD
,@LastFundingFY = isnull(FundingFY,0)
from #temp1
where not statuscd in (35,100,110,120) and FundingFY <= @CurrentProposedFundingFY
order by FundingFY desc, StatusCD desc

-- If LastStatusCD is null then set to 100
if @LastStatusCD is null
select top 1 @LastStatusCD = StatusCD
,@LastFundingFY = FundingFY
from #temp1
where statuscd in (100,110) and FundingFY <= @CurrentProposedFundingFY
order by FundingFY desc, StatusCD desc

-- Return Subtotals for Current Status and Year
select @curFundingAmount = sum(FundingAmount)
,@curCostShareAmount = sum(CostShareAmount)
,@curTotalFLPCost = sum(FLPCost)
,@curOtherFedAmount = sum(OtherFedAmount)
,@curOtherFedCostShareAmount = sum(OtherFedCostShareAmount)
,@curTotalCost = sum(TotalCost)
,@curAcre = sum(Acre)
from #temp1
where FundingFY = @LastFundingFY and StatusCD >= @LastStatusCD

-- Return Project Totals
select @TotalFundingAmount = sum(FundingAmount)
,@TotalCostShareAmount = sum(CostShareAmount)
,@TotalFLPCost = sum(FLPCost)
,@TotalOtherFedAmount = sum(OtherFedAmount)
,@TotalOtherFedCostShareAmount = sum(OtherFedCostShareAmount)
,@TotalCost = sum(TotalCost)
,@TotalAcre = sum(Acre)
from #temp1

-- Return FLP Funding Amount To Date
select
@FundingAmountToDate = sum(FundingAmount)
from #temp1
where StatusCD >= 80 and StatusCD < 120

-- Check for only dropped tracts
if @RC = 0 -- this statement is true only if the first query returned no records
begin
select @LastFundingFY = max(ts.FundingFY)
from (select TractID, max(CreatedOn) as CreatedOn from dbo.TractStatus group by TractID ) cs
inner join dbo.TractStatus ts on cs.TractID = ts.TractID and cs.CreatedOn = ts.CreatedOn
inner join dbo.ProjectTract pt on ts.TractID = pt.TractID
where pt.ProjectID = @ProjectID
end

return @LastStatusCD;
return @LastFundingFY;
return @curFundingAmount;
return @curCostShareAmount;
return @curTotalFLPCost;
return @curOtherFedAmount;
return @curOtherFedCostShareAmount;
return @curTotalCost;
return @curAcre;
return @TotalFundingAmount;
return @TotalCostShareAmount;
return @TotalFLPCost;
return @TotalOtherFedAmount;
return @TotalOtherFedCostShareAmount;
return @TotalCost;
return @TotalAcre;
return @FundingAmountToDate;


drop table #temp1;








share







New contributor




BBSings is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

























    0















    I am developing a java application onWindows 10 using Eclipse Oxygen and SQL JDBC v7.2 and java 1.8 update 202. My code runs fine when I use SQL JDBC v6.0 (sqljdbc42.jar Jan 2017 and java 8), but gives the same java.lang.NullPointerException with SQL JDBC v7.2 (mssql-jdbc-7.2.1.jre8.jar with java 8u202) or (mssql-jdbc-7.2.1.jre11.jar with java 11.0.2) at line rs.next() or any command that attempts to access the recordset (rs) because the recordset value is null.



    (We need to upgrade to v7.2 to be compatible with java 11 as soon as possible. I have many stored procedures that run fine and two stored procedures that cause this java.lang.NullPointerException error for one recordset in their results. I am only including the code for one here.)



    Here is my attempt to fulfill Guidelines when posting JDBC related questions:
    [1] Client side:
    1. Which OS platform are you running on? [SQL Server 2012 on Windows 2012 with dev. client Windows 10 with java 8u202)
    2. Which JVM are you running on? java 8 update 202 (trying to eventually update to java 11.0.2)
    3. What is the connection URL in you app? Rather not share; connection not an issue.
    4. If client fails to connect, what is the client error messages? N/A, connects fine.
    5. Is the client remote or local to the SQL server machine? Remote
    6. Is your client computer in the same domain as the Server computer? (Same domain)
    [2] Server side:
    1. What is the MS SQL version? [ SQL Server 2012]
    2. Does the server start successfully? [YES]
    3. If SQL Server is a named instance, is the SQL browser enabled? [YES]
    4. What is the account that the SQL Server is running under?[Domain Account]
    5. Do you make firewall exception for your SQL server TCP port if you want connect remotely through TCP provider? [YES]
    6. Do you make firewall exception for SQL Browser UDP port 1434? In SQL2000, you still need to make firewall exception for UDP port 1434 in order to support named instance.[not applicable]



    Tips:
    1. If you are executing a complex statement query or stored procedure, please use execute() instead of executeQuery(). [Yes, I use .execute() to execute the CallableStatement that calls the stored procedure in the database.]
    2. If you are using JDBC transactions, do not mix them with T-SQL transactions. [No we are not using transactions. Simple calls to stored procedures that return combination of output parameters and recordsets. We process the recordset information before retrieving output parameters.]



    Database connection works fine and output variables and some recordsets return valid results and work fine.



    The attached stored procedure gives error with JDBC v7.2 when using original complex query for the recordset; it has run fine for years with JDBC v6.0.



    Deploying static tables of the same data works fine in JDBC 7.2.

    Java code:
    // Create database connection and statement
    Connection con = null;



        // Establish the connection.
    SQLServerDataSource ds = new SQLServerDataSource();
    ds.setUser(strDatabaseUser);
    ds.setPassword(strDatabasePassword);
    ds.setServerName(strDatabaseServerName);
    ds.setPortNumber(intDatabaseServerPort);
    ds.setDatabaseName(strDatabaseName);

    try {
    con = ds.getConnection();
    }
    catch (SQLException se) {
    do {
    System.out.println("SQL STATE: " + se.getSQLState());
    System.out.println("ERROR CODE: " + se.getErrorCode());
    System.out.println("MESSAGE: " + se.getMessage());
    System.out.println();
    se = se.getNextException();
    } while (se != null);
    }

    CallableStatement cstmt2 = null;

    if (intArchiveID == -1)
    cstmt2 = con.prepareCall("{call dbo.selProjectTractFunding(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}");
    else
    {
    cstmt2 = con.prepareCall("{call dbo.selProjectTractFundingFromArchive(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}");
    cstmt2.setInt("ArchiveID",intArchiveID);
    }
    cstmt2.setInt("ProjectID",intProjectID);
    cstmt2.setInt("CurrentProposedFundingFY", intCurrentProposedFundingFY);
    cstmt2.registerOutParameter("LastStatusCD", java.sql.Types.INTEGER);
    cstmt2.registerOutParameter("LastFundingFY", java.sql.Types.INTEGER);
    cstmt2.registerOutParameter("curFundingAmount", java.sql.Types.INTEGER);
    cstmt2.registerOutParameter("curCostShareAmount", java.sql.Types.INTEGER);
    cstmt2.registerOutParameter("curTotalFLPCost", java.sql.Types.INTEGER);
    cstmt2.registerOutParameter("curOtherFedAmount", java.sql.Types.INTEGER);
    cstmt2.registerOutParameter("curOtherFedCostShareAmount", java.sql.Types.INTEGER);
    cstmt2.registerOutParameter("curTotalCost", java.sql.Types.INTEGER);
    cstmt2.registerOutParameter("curAcre", java.sql.Types.INTEGER);
    cstmt2.registerOutParameter("TotalFundingAmount", java.sql.Types.INTEGER);
    cstmt2.registerOutParameter("TotalCostShareAmount", java.sql.Types.INTEGER);
    cstmt2.registerOutParameter("TotalFLPCost", java.sql.Types.INTEGER);
    cstmt2.registerOutParameter("TotalOtherFedAmount", java.sql.Types.INTEGER);
    cstmt2.registerOutParameter("TotalOtherFedCostShareAmount", java.sql.Types.INTEGER);
    cstmt2.registerOutParameter("TotalCost", java.sql.Types.INTEGER);
    cstmt2.registerOutParameter("TotalAcre", java.sql.Types.INTEGER);
    cstmt2.registerOutParameter("FundingAmountToDate", java.sql.Types.INTEGER);

    boolean bCstmt2Exe = cstmt2.execute();
    ResultSet rs2=null;
    //if (bCstmt2Exe == true)
    rs2 = cstmt2.getResultSet();


    Table tblTracts = new Table(new float[]{ 6,3,5,5,5,5 });
    tblTracts.setWidth(468f);
    tblTracts.setMarginBottom(12f);
    tblTracts.getAccessibilityProperties().addAttributes(new PdfStructureAttributes("Table").addTextAttribute("Summary","This table lists all tracts in the project and their size, cost, FLP funding, Cost Share and Status." ));

    float fltCellPaddingTop=0f;
    float fltCellPaddingRight=2f;
    float fltCellPaddingLeft=2f;
    float fltCellPaddingBottom=-1f;

    Cell c1 = new Cell().add(new Paragraph("Tract Name")).addStyle(styleTableHeader);
    c1.setTextAlignment(TextAlignment.LEFT);
    c1.setVerticalAlignment(VerticalAlignment.BOTTOM);
    c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
    tblTracts.addHeaderCell(c1);

    c1 = new Cell().add(new Paragraph("Size (ac)")).addStyle(styleTableHeader);
    c1.setTextAlignment(TextAlignment.CENTER);
    c1.setVerticalAlignment(VerticalAlignment.BOTTOM);
    c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
    tblTracts.addHeaderCell(c1);

    c1 = new Cell().add(new Paragraph("Tract Cost")).addStyle(styleTableHeader);
    c1.setTextAlignment(TextAlignment.CENTER);
    c1.setVerticalAlignment(VerticalAlignment.BOTTOM);
    c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
    tblTracts.addHeaderCell(c1);

    c1 = new Cell().add(new Paragraph("FLP Funding")).addStyle(styleTableHeader);
    c1.setTextAlignment(TextAlignment.CENTER);
    c1.setVerticalAlignment(VerticalAlignment.BOTTOM);
    c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
    tblTracts.addHeaderCell(c1);

    c1 = new Cell().add(new Paragraph("Non-Fed Cost Share")).addStyle(styleTableHeader);
    c1.setTextAlignment(TextAlignment.CENTER);
    c1.setVerticalAlignment(VerticalAlignment.BOTTOM);
    c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
    tblTracts.addHeaderCell(c1);

    c1 = new Cell().add(new Paragraph("Status")).addStyle(styleTableHeader);
    c1.setTextAlignment(TextAlignment.CENTER);
    c1.setVerticalAlignment(VerticalAlignment.BOTTOM);
    c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
    tblTracts.addHeaderCell(c1);


    while (rs2.next()){
    int intTractID = rs2.getInt("TractID");
    logger.info("nTractID: "+
    Integer.toString(intTractID));

    c1 = new Cell().add(new Paragraph(rs2.getString("TractName")).addStyle(styleTableCell));
    c1.setTextAlignment(TextAlignment.LEFT);
    c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
    tblTracts.addCell(c1);
    c1 = new Cell().add(new Paragraph(integerFormatter.format(rs2.getInt("Acre"))).addStyle(styleTableCell));
    c1.setTextAlignment(TextAlignment.RIGHT);
    c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
    tblTracts.addCell(c1);
    c1 = new Cell().add(new Paragraph(currencyFormatter.format(rs2.getInt("FLPCost"))).addStyle(styleTableCell));
    c1.setTextAlignment(TextAlignment.RIGHT);
    c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
    tblTracts.addCell(c1);
    c1 = new Cell().add(new Paragraph(currencyFormatter.format(rs2.getInt("FundingAmount"))).addStyle(styleTableCell));
    c1.setTextAlignment(TextAlignment.RIGHT);
    c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
    tblTracts.addCell(c1);
    c1 = new Cell().add(new Paragraph(currencyFormatter.format(rs2.getInt("CostShareAmount"))).addStyle(styleTableCell));
    c1.setTextAlignment(TextAlignment.RIGHT);
    c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
    tblTracts.addCell(c1);
    c1 = new Cell().add(new Paragraph(rs2.getString("DisplayStatusFY")).addStyle(styleTableCell));
    c1.setTextAlignment(TextAlignment.CENTER);
    c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
    tblTracts.addCell(c1);
    }


    int LastFundingFY = cstmt2.getInt("LastFundingFY");
    int curFundingAmount = cstmt2.getInt("curFundingAmount");
    int curCostShareAmount = cstmt2.getInt("curCostShareAmount");
    int curTotalFLPCost = cstmt2.getInt("curTotalFLPCost");
    int curAcre = cstmt2.getInt("curAcre");
    int TotalFLPCost = cstmt2.getInt("TotalFLPCost");
    int TotalAcre = cstmt2.getInt("TotalAcre");
    int FundingAmountToDate = cstmt2.getInt("FundingAmountToDate");

    Table tblFunding = new Table(new float[]{120,60});
    float fltTableFundingCellHeight = 12f;
    tblFunding.setWidth(270F);
    tblFunding.setMarginBottom(16f);
    tblFunding.getAccessibilityProperties().addAttributes(new PdfStructureAttributes("Table").addTextAttribute("Summary","This table provides an overview of the Forest Legacy Program funding history for this project." ));

    c1 = new Cell().add(new Paragraph("FY " + LastFundingFY + " Forest Legacy Program Funding").addStyle(styleTableHeader));
    c1.setTextAlignment(TextAlignment.RIGHT);
    c1.setBorder(Border.NO_BORDER);
    c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
    c1.setHeight(fltTableFundingCellHeight);
    c1.getAccessibilityProperties().setRole(StandardRoles.TH);
    tblFunding.addCell(c1);
    c1 = new Cell().add(new Paragraph(currencyFormatter.format(curFundingAmount)).addStyle(styleTableHeader));
    c1.setTextAlignment(TextAlignment.RIGHT);
    c1.setBorder(Border.NO_BORDER);
    c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
    c1.setHeight(fltTableFundingCellHeight);
    tblFunding.addCell(c1);

    c1 = new Cell().add(new Paragraph("FY " + LastFundingFY + " Non-Federal Cost Share").addStyle(styleTableHeader));
    c1.setTextAlignment(TextAlignment.RIGHT);
    c1.setBorder(Border.NO_BORDER);
    c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
    c1.setHeight(fltTableFundingCellHeight);
    c1.getAccessibilityProperties().setRole(StandardRoles.TH);
    tblFunding.addCell(c1);
    c1 = new Cell().add(new Paragraph(currencyFormatter.format(curCostShareAmount)).addStyle(styleTableHeader));
    c1.setTextAlignment(TextAlignment.RIGHT);
    c1.setBorder(Border.NO_BORDER);
    c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
    c1.setHeight(fltTableFundingCellHeight);
    tblFunding.addCell(c1);

    c1 = new Cell().add(new Paragraph("FY " + LastFundingFY + " Project Costs").addStyle(styleTableHeader));
    c1.setTextAlignment(TextAlignment.RIGHT);
    c1.setBorder(Border.NO_BORDER);
    c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
    c1.setHeight(fltTableFundingCellHeight);
    c1.getAccessibilityProperties().setRole(StandardRoles.TH);
    tblFunding.addCell(c1);
    c1 = new Cell().add(new Paragraph(currencyFormatter.format(curTotalFLPCost)).addStyle(styleTableHeader));
    c1.setTextAlignment(TextAlignment.RIGHT);
    c1.setBorder(Border.NO_BORDER);
    c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
    c1.setHeight(fltTableFundingCellHeight);
    tblFunding.addCell(c1);


    c1 = new Cell().add(new Paragraph("FY " + LastFundingFY + " Project Acres").addStyle(styleTableHeader));
    c1.setTextAlignment(TextAlignment.RIGHT);
    c1.setBorder(Border.NO_BORDER);
    c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom + 10f, fltCellPaddingLeft);
    c1.setHeight(fltTableFundingCellHeight);
    c1.getAccessibilityProperties().setRole(StandardRoles.TH);
    tblFunding.addCell(c1);
    c1 = new Cell().add(new Paragraph(integerFormatter.format(curAcre)).addStyle(styleTableHeader));
    c1.setTextAlignment(TextAlignment.RIGHT);
    c1.setBorder(Border.NO_BORDER);
    c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom + 10f, fltCellPaddingLeft);
    c1.setHeight(fltTableFundingCellHeight);
    tblFunding.addCell(c1);

    c1 = new Cell().add(new Paragraph("Forest Legacy Funding To Date").addStyle(styleTableHeader));
    c1.setTextAlignment(TextAlignment.RIGHT);
    c1.setBorder(Border.NO_BORDER);
    c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
    c1.setHeight(fltTableFundingCellHeight);
    c1.getAccessibilityProperties().setRole(StandardRoles.TH);
    tblFunding.addCell(c1);
    c1 = new Cell().add(new Paragraph(currencyFormatter.format(FundingAmountToDate)).addStyle(styleTableHeader));
    c1.setTextAlignment(TextAlignment.RIGHT);
    c1.setBorder(Border.NO_BORDER);
    c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
    c1.setHeight(fltTableFundingCellHeight);
    tblFunding.addCell(c1);

    c1 = new Cell().add(new Paragraph("Total Project Costs").addStyle(styleTableHeader));
    c1.setTextAlignment(TextAlignment.RIGHT);
    c1.setBorder(Border.NO_BORDER);
    c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
    c1.setHeight(fltTableFundingCellHeight);
    c1.getAccessibilityProperties().setRole(StandardRoles.TH);
    tblFunding.addCell(c1);
    c1 = new Cell().add(new Paragraph(currencyFormatter.format(TotalFLPCost)).addStyle(styleTableHeader));
    c1.setTextAlignment(TextAlignment.RIGHT);
    c1.setBorder(Border.NO_BORDER);
    c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
    c1.setHeight(fltTableFundingCellHeight);
    tblFunding.addCell(c1);

    c1 = new Cell().add(new Paragraph("Total Project Acres").addStyle(styleTableHeader));
    c1.setTextAlignment(TextAlignment.RIGHT);
    c1.setBorder(Border.NO_BORDER);
    c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
    c1.setHeight(fltTableFundingCellHeight);
    c1.getAccessibilityProperties().setRole(StandardRoles.TH);
    tblFunding.addCell(c1);
    c1 = new Cell().add(new Paragraph(integerFormatter.format(TotalAcre)).addStyle(styleTableHeader));
    c1.setTextAlignment(TextAlignment.RIGHT);
    c1.setBorder(Border.NO_BORDER);
    c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
    c1.setHeight(fltTableFundingCellHeight);
    tblFunding.addCell(c1);

    cstmt2.close();


    Here is the Stored Procedure that gives error. (Please note comment of sql query that if converted to static table, resolves the error!):



    /****** Object: StoredProcedure [dbo].[selProjectTractFunding] Script Date: 2/20/2019 3:48:22 PM ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    */



    CREATE PROCEDURE [dbo].[selProjectTractFunding] ( @ProjectID int,
    @CurrentProposedFundingFY int, @LastStatusCD int out, @LastFundingFY int out,
    @curFundingAmount int out, @curCostShareAmount int out,
    @curTotalFLPCost int out, @curOtherFedAmount int out,
    @curOtherFedCostShareAmount int out, @curTotalCost int out,
    @curAcre int out, @TotalFundingAmount int out,
    @TotalCostShareAmount int out, @TotalFLPCost int out,
    @TotalOtherFedAmount int out, @TotalOtherFedCostShareAmount int out,
    @TotalCost int out, @TotalAcre int out,
    @FundingAmountToDate int out )
    AS
    declare @RC int



    /***  All works FINE if I convert this first query to a static table TEMP1 and replace it with "select * from temp1".  Does not work from temporary table #temp1 as coded here.  ***/
    select pt.ProjectID
    ,t.TractID
    ,t.TractName
    ,t.PurchaseTypeCD
    ,cast(isnull(t.Acre,0) as int) as Acre
    ,cast(isnull(t.FundingAmount,0) as bigint) as FundingAmount
    ,cast(isnull(costshare.CostShareAmount,0) as bigint) as CostShareAmount
    ,cast((isnull(t.FundingAmount,0) + isnull(costshare.CostShareAmount,0)) as bigint) as FLPCost
    ,cast(isnull(ofed.OtherFedAmount,0) as bigint) as OtherFedAmount
    ,cast(isnull(ofed.OtherFedCostShareAmount,0) as bigint) as OtherFedCostShareAmount
    ,cast((isnull(t.FundingAmount,0) + isnull(costshare.CostShareAmount,0) + isnull(ofed.OtherFedAmount,0) + isnull(ofed.OtherFedCostShareAmount,0)) as bigint) as TotalCost
    ,cast(dbo.getFY(CompleteDate) as int) as CompleteFY
    ,ts.StatusCD
    ,s.Status
    ,s.DisplayStatus
    ,cast(case when t.CompleteDate is null then s.DisplayStatus + ' ' + cast(ts.FundingFY as varchar) else s.DisplayStatus + ' ' + cast(dbo.getFY(t.CompleteDate) as varchar) end as varchar) as DisplayStatusFY
    ,ts.FundingFY
    ,ts.CreatedOn
    into #temp1
    from (select TractID, max(CreatedOn) as CreatedOn from dbo.TractStatus group by TractID ) cs
    inner join dbo.TractStatus ts on cs.TractID = ts.TractID and cs.CreatedOn = ts.CreatedOn
    inner join dbo.Tract t on ts.TractID = t.TractID
    inner join dbo.ProjectTract pt on t.TractID = pt.TractID
    left outer join (select TractID, Sum(OtherFedAmount) as OtherFedAmount, sum(OtherFedCostShareAmount) as OtherFedCostShareAmount from dbo.OtherFederal group by TractID ) ofed on ofed.TractID = t.TractID
    left outer join (select TractID, sum(CostShareAmount) as CostShareAmount from dbo.CostShare group by TractID) costshare on costshare.TractID = t.TractID
    inner join dbo._refStatus s on ts.StatusCD = s.StatusCD
    where pt.ProjectID = @ProjectID
    and ts.StatusCD <> 120

    set @RC = @@RowCount

    -- Return recorset of tract details
    select * from #temp1 t
    order by t.TractName

    -- Get Last or Latest Status (other than closed/complete) for latest FundingFY for Project
    select top 1 @LastStatusCD = StatusCD
    ,@LastFundingFY = isnull(FundingFY,0)
    from #temp1
    where not statuscd in (35,100,110,120) and FundingFY <= @CurrentProposedFundingFY
    order by FundingFY desc, StatusCD desc

    -- If LastStatusCD is null then set to 100
    if @LastStatusCD is null
    select top 1 @LastStatusCD = StatusCD
    ,@LastFundingFY = FundingFY
    from #temp1
    where statuscd in (100,110) and FundingFY <= @CurrentProposedFundingFY
    order by FundingFY desc, StatusCD desc

    -- Return Subtotals for Current Status and Year
    select @curFundingAmount = sum(FundingAmount)
    ,@curCostShareAmount = sum(CostShareAmount)
    ,@curTotalFLPCost = sum(FLPCost)
    ,@curOtherFedAmount = sum(OtherFedAmount)
    ,@curOtherFedCostShareAmount = sum(OtherFedCostShareAmount)
    ,@curTotalCost = sum(TotalCost)
    ,@curAcre = sum(Acre)
    from #temp1
    where FundingFY = @LastFundingFY and StatusCD >= @LastStatusCD

    -- Return Project Totals
    select @TotalFundingAmount = sum(FundingAmount)
    ,@TotalCostShareAmount = sum(CostShareAmount)
    ,@TotalFLPCost = sum(FLPCost)
    ,@TotalOtherFedAmount = sum(OtherFedAmount)
    ,@TotalOtherFedCostShareAmount = sum(OtherFedCostShareAmount)
    ,@TotalCost = sum(TotalCost)
    ,@TotalAcre = sum(Acre)
    from #temp1

    -- Return FLP Funding Amount To Date
    select
    @FundingAmountToDate = sum(FundingAmount)
    from #temp1
    where StatusCD >= 80 and StatusCD < 120

    -- Check for only dropped tracts
    if @RC = 0 -- this statement is true only if the first query returned no records
    begin
    select @LastFundingFY = max(ts.FundingFY)
    from (select TractID, max(CreatedOn) as CreatedOn from dbo.TractStatus group by TractID ) cs
    inner join dbo.TractStatus ts on cs.TractID = ts.TractID and cs.CreatedOn = ts.CreatedOn
    inner join dbo.ProjectTract pt on ts.TractID = pt.TractID
    where pt.ProjectID = @ProjectID
    end

    return @LastStatusCD;
    return @LastFundingFY;
    return @curFundingAmount;
    return @curCostShareAmount;
    return @curTotalFLPCost;
    return @curOtherFedAmount;
    return @curOtherFedCostShareAmount;
    return @curTotalCost;
    return @curAcre;
    return @TotalFundingAmount;
    return @TotalCostShareAmount;
    return @TotalFLPCost;
    return @TotalOtherFedAmount;
    return @TotalOtherFedCostShareAmount;
    return @TotalCost;
    return @TotalAcre;
    return @FundingAmountToDate;


    drop table #temp1;








    share







    New contributor




    BBSings is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.























      0












      0








      0








      I am developing a java application onWindows 10 using Eclipse Oxygen and SQL JDBC v7.2 and java 1.8 update 202. My code runs fine when I use SQL JDBC v6.0 (sqljdbc42.jar Jan 2017 and java 8), but gives the same java.lang.NullPointerException with SQL JDBC v7.2 (mssql-jdbc-7.2.1.jre8.jar with java 8u202) or (mssql-jdbc-7.2.1.jre11.jar with java 11.0.2) at line rs.next() or any command that attempts to access the recordset (rs) because the recordset value is null.



      (We need to upgrade to v7.2 to be compatible with java 11 as soon as possible. I have many stored procedures that run fine and two stored procedures that cause this java.lang.NullPointerException error for one recordset in their results. I am only including the code for one here.)



      Here is my attempt to fulfill Guidelines when posting JDBC related questions:
      [1] Client side:
      1. Which OS platform are you running on? [SQL Server 2012 on Windows 2012 with dev. client Windows 10 with java 8u202)
      2. Which JVM are you running on? java 8 update 202 (trying to eventually update to java 11.0.2)
      3. What is the connection URL in you app? Rather not share; connection not an issue.
      4. If client fails to connect, what is the client error messages? N/A, connects fine.
      5. Is the client remote or local to the SQL server machine? Remote
      6. Is your client computer in the same domain as the Server computer? (Same domain)
      [2] Server side:
      1. What is the MS SQL version? [ SQL Server 2012]
      2. Does the server start successfully? [YES]
      3. If SQL Server is a named instance, is the SQL browser enabled? [YES]
      4. What is the account that the SQL Server is running under?[Domain Account]
      5. Do you make firewall exception for your SQL server TCP port if you want connect remotely through TCP provider? [YES]
      6. Do you make firewall exception for SQL Browser UDP port 1434? In SQL2000, you still need to make firewall exception for UDP port 1434 in order to support named instance.[not applicable]



      Tips:
      1. If you are executing a complex statement query or stored procedure, please use execute() instead of executeQuery(). [Yes, I use .execute() to execute the CallableStatement that calls the stored procedure in the database.]
      2. If you are using JDBC transactions, do not mix them with T-SQL transactions. [No we are not using transactions. Simple calls to stored procedures that return combination of output parameters and recordsets. We process the recordset information before retrieving output parameters.]



      Database connection works fine and output variables and some recordsets return valid results and work fine.



      The attached stored procedure gives error with JDBC v7.2 when using original complex query for the recordset; it has run fine for years with JDBC v6.0.



      Deploying static tables of the same data works fine in JDBC 7.2.

      Java code:
      // Create database connection and statement
      Connection con = null;



          // Establish the connection.
      SQLServerDataSource ds = new SQLServerDataSource();
      ds.setUser(strDatabaseUser);
      ds.setPassword(strDatabasePassword);
      ds.setServerName(strDatabaseServerName);
      ds.setPortNumber(intDatabaseServerPort);
      ds.setDatabaseName(strDatabaseName);

      try {
      con = ds.getConnection();
      }
      catch (SQLException se) {
      do {
      System.out.println("SQL STATE: " + se.getSQLState());
      System.out.println("ERROR CODE: " + se.getErrorCode());
      System.out.println("MESSAGE: " + se.getMessage());
      System.out.println();
      se = se.getNextException();
      } while (se != null);
      }

      CallableStatement cstmt2 = null;

      if (intArchiveID == -1)
      cstmt2 = con.prepareCall("{call dbo.selProjectTractFunding(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}");
      else
      {
      cstmt2 = con.prepareCall("{call dbo.selProjectTractFundingFromArchive(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}");
      cstmt2.setInt("ArchiveID",intArchiveID);
      }
      cstmt2.setInt("ProjectID",intProjectID);
      cstmt2.setInt("CurrentProposedFundingFY", intCurrentProposedFundingFY);
      cstmt2.registerOutParameter("LastStatusCD", java.sql.Types.INTEGER);
      cstmt2.registerOutParameter("LastFundingFY", java.sql.Types.INTEGER);
      cstmt2.registerOutParameter("curFundingAmount", java.sql.Types.INTEGER);
      cstmt2.registerOutParameter("curCostShareAmount", java.sql.Types.INTEGER);
      cstmt2.registerOutParameter("curTotalFLPCost", java.sql.Types.INTEGER);
      cstmt2.registerOutParameter("curOtherFedAmount", java.sql.Types.INTEGER);
      cstmt2.registerOutParameter("curOtherFedCostShareAmount", java.sql.Types.INTEGER);
      cstmt2.registerOutParameter("curTotalCost", java.sql.Types.INTEGER);
      cstmt2.registerOutParameter("curAcre", java.sql.Types.INTEGER);
      cstmt2.registerOutParameter("TotalFundingAmount", java.sql.Types.INTEGER);
      cstmt2.registerOutParameter("TotalCostShareAmount", java.sql.Types.INTEGER);
      cstmt2.registerOutParameter("TotalFLPCost", java.sql.Types.INTEGER);
      cstmt2.registerOutParameter("TotalOtherFedAmount", java.sql.Types.INTEGER);
      cstmt2.registerOutParameter("TotalOtherFedCostShareAmount", java.sql.Types.INTEGER);
      cstmt2.registerOutParameter("TotalCost", java.sql.Types.INTEGER);
      cstmt2.registerOutParameter("TotalAcre", java.sql.Types.INTEGER);
      cstmt2.registerOutParameter("FundingAmountToDate", java.sql.Types.INTEGER);

      boolean bCstmt2Exe = cstmt2.execute();
      ResultSet rs2=null;
      //if (bCstmt2Exe == true)
      rs2 = cstmt2.getResultSet();


      Table tblTracts = new Table(new float[]{ 6,3,5,5,5,5 });
      tblTracts.setWidth(468f);
      tblTracts.setMarginBottom(12f);
      tblTracts.getAccessibilityProperties().addAttributes(new PdfStructureAttributes("Table").addTextAttribute("Summary","This table lists all tracts in the project and their size, cost, FLP funding, Cost Share and Status." ));

      float fltCellPaddingTop=0f;
      float fltCellPaddingRight=2f;
      float fltCellPaddingLeft=2f;
      float fltCellPaddingBottom=-1f;

      Cell c1 = new Cell().add(new Paragraph("Tract Name")).addStyle(styleTableHeader);
      c1.setTextAlignment(TextAlignment.LEFT);
      c1.setVerticalAlignment(VerticalAlignment.BOTTOM);
      c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
      tblTracts.addHeaderCell(c1);

      c1 = new Cell().add(new Paragraph("Size (ac)")).addStyle(styleTableHeader);
      c1.setTextAlignment(TextAlignment.CENTER);
      c1.setVerticalAlignment(VerticalAlignment.BOTTOM);
      c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
      tblTracts.addHeaderCell(c1);

      c1 = new Cell().add(new Paragraph("Tract Cost")).addStyle(styleTableHeader);
      c1.setTextAlignment(TextAlignment.CENTER);
      c1.setVerticalAlignment(VerticalAlignment.BOTTOM);
      c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
      tblTracts.addHeaderCell(c1);

      c1 = new Cell().add(new Paragraph("FLP Funding")).addStyle(styleTableHeader);
      c1.setTextAlignment(TextAlignment.CENTER);
      c1.setVerticalAlignment(VerticalAlignment.BOTTOM);
      c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
      tblTracts.addHeaderCell(c1);

      c1 = new Cell().add(new Paragraph("Non-Fed Cost Share")).addStyle(styleTableHeader);
      c1.setTextAlignment(TextAlignment.CENTER);
      c1.setVerticalAlignment(VerticalAlignment.BOTTOM);
      c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
      tblTracts.addHeaderCell(c1);

      c1 = new Cell().add(new Paragraph("Status")).addStyle(styleTableHeader);
      c1.setTextAlignment(TextAlignment.CENTER);
      c1.setVerticalAlignment(VerticalAlignment.BOTTOM);
      c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
      tblTracts.addHeaderCell(c1);


      while (rs2.next()){
      int intTractID = rs2.getInt("TractID");
      logger.info("nTractID: "+
      Integer.toString(intTractID));

      c1 = new Cell().add(new Paragraph(rs2.getString("TractName")).addStyle(styleTableCell));
      c1.setTextAlignment(TextAlignment.LEFT);
      c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
      tblTracts.addCell(c1);
      c1 = new Cell().add(new Paragraph(integerFormatter.format(rs2.getInt("Acre"))).addStyle(styleTableCell));
      c1.setTextAlignment(TextAlignment.RIGHT);
      c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
      tblTracts.addCell(c1);
      c1 = new Cell().add(new Paragraph(currencyFormatter.format(rs2.getInt("FLPCost"))).addStyle(styleTableCell));
      c1.setTextAlignment(TextAlignment.RIGHT);
      c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
      tblTracts.addCell(c1);
      c1 = new Cell().add(new Paragraph(currencyFormatter.format(rs2.getInt("FundingAmount"))).addStyle(styleTableCell));
      c1.setTextAlignment(TextAlignment.RIGHT);
      c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
      tblTracts.addCell(c1);
      c1 = new Cell().add(new Paragraph(currencyFormatter.format(rs2.getInt("CostShareAmount"))).addStyle(styleTableCell));
      c1.setTextAlignment(TextAlignment.RIGHT);
      c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
      tblTracts.addCell(c1);
      c1 = new Cell().add(new Paragraph(rs2.getString("DisplayStatusFY")).addStyle(styleTableCell));
      c1.setTextAlignment(TextAlignment.CENTER);
      c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
      tblTracts.addCell(c1);
      }


      int LastFundingFY = cstmt2.getInt("LastFundingFY");
      int curFundingAmount = cstmt2.getInt("curFundingAmount");
      int curCostShareAmount = cstmt2.getInt("curCostShareAmount");
      int curTotalFLPCost = cstmt2.getInt("curTotalFLPCost");
      int curAcre = cstmt2.getInt("curAcre");
      int TotalFLPCost = cstmt2.getInt("TotalFLPCost");
      int TotalAcre = cstmt2.getInt("TotalAcre");
      int FundingAmountToDate = cstmt2.getInt("FundingAmountToDate");

      Table tblFunding = new Table(new float[]{120,60});
      float fltTableFundingCellHeight = 12f;
      tblFunding.setWidth(270F);
      tblFunding.setMarginBottom(16f);
      tblFunding.getAccessibilityProperties().addAttributes(new PdfStructureAttributes("Table").addTextAttribute("Summary","This table provides an overview of the Forest Legacy Program funding history for this project." ));

      c1 = new Cell().add(new Paragraph("FY " + LastFundingFY + " Forest Legacy Program Funding").addStyle(styleTableHeader));
      c1.setTextAlignment(TextAlignment.RIGHT);
      c1.setBorder(Border.NO_BORDER);
      c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
      c1.setHeight(fltTableFundingCellHeight);
      c1.getAccessibilityProperties().setRole(StandardRoles.TH);
      tblFunding.addCell(c1);
      c1 = new Cell().add(new Paragraph(currencyFormatter.format(curFundingAmount)).addStyle(styleTableHeader));
      c1.setTextAlignment(TextAlignment.RIGHT);
      c1.setBorder(Border.NO_BORDER);
      c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
      c1.setHeight(fltTableFundingCellHeight);
      tblFunding.addCell(c1);

      c1 = new Cell().add(new Paragraph("FY " + LastFundingFY + " Non-Federal Cost Share").addStyle(styleTableHeader));
      c1.setTextAlignment(TextAlignment.RIGHT);
      c1.setBorder(Border.NO_BORDER);
      c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
      c1.setHeight(fltTableFundingCellHeight);
      c1.getAccessibilityProperties().setRole(StandardRoles.TH);
      tblFunding.addCell(c1);
      c1 = new Cell().add(new Paragraph(currencyFormatter.format(curCostShareAmount)).addStyle(styleTableHeader));
      c1.setTextAlignment(TextAlignment.RIGHT);
      c1.setBorder(Border.NO_BORDER);
      c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
      c1.setHeight(fltTableFundingCellHeight);
      tblFunding.addCell(c1);

      c1 = new Cell().add(new Paragraph("FY " + LastFundingFY + " Project Costs").addStyle(styleTableHeader));
      c1.setTextAlignment(TextAlignment.RIGHT);
      c1.setBorder(Border.NO_BORDER);
      c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
      c1.setHeight(fltTableFundingCellHeight);
      c1.getAccessibilityProperties().setRole(StandardRoles.TH);
      tblFunding.addCell(c1);
      c1 = new Cell().add(new Paragraph(currencyFormatter.format(curTotalFLPCost)).addStyle(styleTableHeader));
      c1.setTextAlignment(TextAlignment.RIGHT);
      c1.setBorder(Border.NO_BORDER);
      c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
      c1.setHeight(fltTableFundingCellHeight);
      tblFunding.addCell(c1);


      c1 = new Cell().add(new Paragraph("FY " + LastFundingFY + " Project Acres").addStyle(styleTableHeader));
      c1.setTextAlignment(TextAlignment.RIGHT);
      c1.setBorder(Border.NO_BORDER);
      c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom + 10f, fltCellPaddingLeft);
      c1.setHeight(fltTableFundingCellHeight);
      c1.getAccessibilityProperties().setRole(StandardRoles.TH);
      tblFunding.addCell(c1);
      c1 = new Cell().add(new Paragraph(integerFormatter.format(curAcre)).addStyle(styleTableHeader));
      c1.setTextAlignment(TextAlignment.RIGHT);
      c1.setBorder(Border.NO_BORDER);
      c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom + 10f, fltCellPaddingLeft);
      c1.setHeight(fltTableFundingCellHeight);
      tblFunding.addCell(c1);

      c1 = new Cell().add(new Paragraph("Forest Legacy Funding To Date").addStyle(styleTableHeader));
      c1.setTextAlignment(TextAlignment.RIGHT);
      c1.setBorder(Border.NO_BORDER);
      c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
      c1.setHeight(fltTableFundingCellHeight);
      c1.getAccessibilityProperties().setRole(StandardRoles.TH);
      tblFunding.addCell(c1);
      c1 = new Cell().add(new Paragraph(currencyFormatter.format(FundingAmountToDate)).addStyle(styleTableHeader));
      c1.setTextAlignment(TextAlignment.RIGHT);
      c1.setBorder(Border.NO_BORDER);
      c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
      c1.setHeight(fltTableFundingCellHeight);
      tblFunding.addCell(c1);

      c1 = new Cell().add(new Paragraph("Total Project Costs").addStyle(styleTableHeader));
      c1.setTextAlignment(TextAlignment.RIGHT);
      c1.setBorder(Border.NO_BORDER);
      c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
      c1.setHeight(fltTableFundingCellHeight);
      c1.getAccessibilityProperties().setRole(StandardRoles.TH);
      tblFunding.addCell(c1);
      c1 = new Cell().add(new Paragraph(currencyFormatter.format(TotalFLPCost)).addStyle(styleTableHeader));
      c1.setTextAlignment(TextAlignment.RIGHT);
      c1.setBorder(Border.NO_BORDER);
      c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
      c1.setHeight(fltTableFundingCellHeight);
      tblFunding.addCell(c1);

      c1 = new Cell().add(new Paragraph("Total Project Acres").addStyle(styleTableHeader));
      c1.setTextAlignment(TextAlignment.RIGHT);
      c1.setBorder(Border.NO_BORDER);
      c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
      c1.setHeight(fltTableFundingCellHeight);
      c1.getAccessibilityProperties().setRole(StandardRoles.TH);
      tblFunding.addCell(c1);
      c1 = new Cell().add(new Paragraph(integerFormatter.format(TotalAcre)).addStyle(styleTableHeader));
      c1.setTextAlignment(TextAlignment.RIGHT);
      c1.setBorder(Border.NO_BORDER);
      c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
      c1.setHeight(fltTableFundingCellHeight);
      tblFunding.addCell(c1);

      cstmt2.close();


      Here is the Stored Procedure that gives error. (Please note comment of sql query that if converted to static table, resolves the error!):



      /****** Object: StoredProcedure [dbo].[selProjectTractFunding] Script Date: 2/20/2019 3:48:22 PM ******/
      SET ANSI_NULLS ON
      GO
      SET QUOTED_IDENTIFIER ON
      GO
      */



      CREATE PROCEDURE [dbo].[selProjectTractFunding] ( @ProjectID int,
      @CurrentProposedFundingFY int, @LastStatusCD int out, @LastFundingFY int out,
      @curFundingAmount int out, @curCostShareAmount int out,
      @curTotalFLPCost int out, @curOtherFedAmount int out,
      @curOtherFedCostShareAmount int out, @curTotalCost int out,
      @curAcre int out, @TotalFundingAmount int out,
      @TotalCostShareAmount int out, @TotalFLPCost int out,
      @TotalOtherFedAmount int out, @TotalOtherFedCostShareAmount int out,
      @TotalCost int out, @TotalAcre int out,
      @FundingAmountToDate int out )
      AS
      declare @RC int



      /***  All works FINE if I convert this first query to a static table TEMP1 and replace it with "select * from temp1".  Does not work from temporary table #temp1 as coded here.  ***/
      select pt.ProjectID
      ,t.TractID
      ,t.TractName
      ,t.PurchaseTypeCD
      ,cast(isnull(t.Acre,0) as int) as Acre
      ,cast(isnull(t.FundingAmount,0) as bigint) as FundingAmount
      ,cast(isnull(costshare.CostShareAmount,0) as bigint) as CostShareAmount
      ,cast((isnull(t.FundingAmount,0) + isnull(costshare.CostShareAmount,0)) as bigint) as FLPCost
      ,cast(isnull(ofed.OtherFedAmount,0) as bigint) as OtherFedAmount
      ,cast(isnull(ofed.OtherFedCostShareAmount,0) as bigint) as OtherFedCostShareAmount
      ,cast((isnull(t.FundingAmount,0) + isnull(costshare.CostShareAmount,0) + isnull(ofed.OtherFedAmount,0) + isnull(ofed.OtherFedCostShareAmount,0)) as bigint) as TotalCost
      ,cast(dbo.getFY(CompleteDate) as int) as CompleteFY
      ,ts.StatusCD
      ,s.Status
      ,s.DisplayStatus
      ,cast(case when t.CompleteDate is null then s.DisplayStatus + ' ' + cast(ts.FundingFY as varchar) else s.DisplayStatus + ' ' + cast(dbo.getFY(t.CompleteDate) as varchar) end as varchar) as DisplayStatusFY
      ,ts.FundingFY
      ,ts.CreatedOn
      into #temp1
      from (select TractID, max(CreatedOn) as CreatedOn from dbo.TractStatus group by TractID ) cs
      inner join dbo.TractStatus ts on cs.TractID = ts.TractID and cs.CreatedOn = ts.CreatedOn
      inner join dbo.Tract t on ts.TractID = t.TractID
      inner join dbo.ProjectTract pt on t.TractID = pt.TractID
      left outer join (select TractID, Sum(OtherFedAmount) as OtherFedAmount, sum(OtherFedCostShareAmount) as OtherFedCostShareAmount from dbo.OtherFederal group by TractID ) ofed on ofed.TractID = t.TractID
      left outer join (select TractID, sum(CostShareAmount) as CostShareAmount from dbo.CostShare group by TractID) costshare on costshare.TractID = t.TractID
      inner join dbo._refStatus s on ts.StatusCD = s.StatusCD
      where pt.ProjectID = @ProjectID
      and ts.StatusCD <> 120

      set @RC = @@RowCount

      -- Return recorset of tract details
      select * from #temp1 t
      order by t.TractName

      -- Get Last or Latest Status (other than closed/complete) for latest FundingFY for Project
      select top 1 @LastStatusCD = StatusCD
      ,@LastFundingFY = isnull(FundingFY,0)
      from #temp1
      where not statuscd in (35,100,110,120) and FundingFY <= @CurrentProposedFundingFY
      order by FundingFY desc, StatusCD desc

      -- If LastStatusCD is null then set to 100
      if @LastStatusCD is null
      select top 1 @LastStatusCD = StatusCD
      ,@LastFundingFY = FundingFY
      from #temp1
      where statuscd in (100,110) and FundingFY <= @CurrentProposedFundingFY
      order by FundingFY desc, StatusCD desc

      -- Return Subtotals for Current Status and Year
      select @curFundingAmount = sum(FundingAmount)
      ,@curCostShareAmount = sum(CostShareAmount)
      ,@curTotalFLPCost = sum(FLPCost)
      ,@curOtherFedAmount = sum(OtherFedAmount)
      ,@curOtherFedCostShareAmount = sum(OtherFedCostShareAmount)
      ,@curTotalCost = sum(TotalCost)
      ,@curAcre = sum(Acre)
      from #temp1
      where FundingFY = @LastFundingFY and StatusCD >= @LastStatusCD

      -- Return Project Totals
      select @TotalFundingAmount = sum(FundingAmount)
      ,@TotalCostShareAmount = sum(CostShareAmount)
      ,@TotalFLPCost = sum(FLPCost)
      ,@TotalOtherFedAmount = sum(OtherFedAmount)
      ,@TotalOtherFedCostShareAmount = sum(OtherFedCostShareAmount)
      ,@TotalCost = sum(TotalCost)
      ,@TotalAcre = sum(Acre)
      from #temp1

      -- Return FLP Funding Amount To Date
      select
      @FundingAmountToDate = sum(FundingAmount)
      from #temp1
      where StatusCD >= 80 and StatusCD < 120

      -- Check for only dropped tracts
      if @RC = 0 -- this statement is true only if the first query returned no records
      begin
      select @LastFundingFY = max(ts.FundingFY)
      from (select TractID, max(CreatedOn) as CreatedOn from dbo.TractStatus group by TractID ) cs
      inner join dbo.TractStatus ts on cs.TractID = ts.TractID and cs.CreatedOn = ts.CreatedOn
      inner join dbo.ProjectTract pt on ts.TractID = pt.TractID
      where pt.ProjectID = @ProjectID
      end

      return @LastStatusCD;
      return @LastFundingFY;
      return @curFundingAmount;
      return @curCostShareAmount;
      return @curTotalFLPCost;
      return @curOtherFedAmount;
      return @curOtherFedCostShareAmount;
      return @curTotalCost;
      return @curAcre;
      return @TotalFundingAmount;
      return @TotalCostShareAmount;
      return @TotalFLPCost;
      return @TotalOtherFedAmount;
      return @TotalOtherFedCostShareAmount;
      return @TotalCost;
      return @TotalAcre;
      return @FundingAmountToDate;


      drop table #temp1;








      share







      New contributor




      BBSings is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.












      I am developing a java application onWindows 10 using Eclipse Oxygen and SQL JDBC v7.2 and java 1.8 update 202. My code runs fine when I use SQL JDBC v6.0 (sqljdbc42.jar Jan 2017 and java 8), but gives the same java.lang.NullPointerException with SQL JDBC v7.2 (mssql-jdbc-7.2.1.jre8.jar with java 8u202) or (mssql-jdbc-7.2.1.jre11.jar with java 11.0.2) at line rs.next() or any command that attempts to access the recordset (rs) because the recordset value is null.



      (We need to upgrade to v7.2 to be compatible with java 11 as soon as possible. I have many stored procedures that run fine and two stored procedures that cause this java.lang.NullPointerException error for one recordset in their results. I am only including the code for one here.)



      Here is my attempt to fulfill Guidelines when posting JDBC related questions:
      [1] Client side:
      1. Which OS platform are you running on? [SQL Server 2012 on Windows 2012 with dev. client Windows 10 with java 8u202)
      2. Which JVM are you running on? java 8 update 202 (trying to eventually update to java 11.0.2)
      3. What is the connection URL in you app? Rather not share; connection not an issue.
      4. If client fails to connect, what is the client error messages? N/A, connects fine.
      5. Is the client remote or local to the SQL server machine? Remote
      6. Is your client computer in the same domain as the Server computer? (Same domain)
      [2] Server side:
      1. What is the MS SQL version? [ SQL Server 2012]
      2. Does the server start successfully? [YES]
      3. If SQL Server is a named instance, is the SQL browser enabled? [YES]
      4. What is the account that the SQL Server is running under?[Domain Account]
      5. Do you make firewall exception for your SQL server TCP port if you want connect remotely through TCP provider? [YES]
      6. Do you make firewall exception for SQL Browser UDP port 1434? In SQL2000, you still need to make firewall exception for UDP port 1434 in order to support named instance.[not applicable]



      Tips:
      1. If you are executing a complex statement query or stored procedure, please use execute() instead of executeQuery(). [Yes, I use .execute() to execute the CallableStatement that calls the stored procedure in the database.]
      2. If you are using JDBC transactions, do not mix them with T-SQL transactions. [No we are not using transactions. Simple calls to stored procedures that return combination of output parameters and recordsets. We process the recordset information before retrieving output parameters.]



      Database connection works fine and output variables and some recordsets return valid results and work fine.



      The attached stored procedure gives error with JDBC v7.2 when using original complex query for the recordset; it has run fine for years with JDBC v6.0.



      Deploying static tables of the same data works fine in JDBC 7.2.

      Java code:
      // Create database connection and statement
      Connection con = null;



          // Establish the connection.
      SQLServerDataSource ds = new SQLServerDataSource();
      ds.setUser(strDatabaseUser);
      ds.setPassword(strDatabasePassword);
      ds.setServerName(strDatabaseServerName);
      ds.setPortNumber(intDatabaseServerPort);
      ds.setDatabaseName(strDatabaseName);

      try {
      con = ds.getConnection();
      }
      catch (SQLException se) {
      do {
      System.out.println("SQL STATE: " + se.getSQLState());
      System.out.println("ERROR CODE: " + se.getErrorCode());
      System.out.println("MESSAGE: " + se.getMessage());
      System.out.println();
      se = se.getNextException();
      } while (se != null);
      }

      CallableStatement cstmt2 = null;

      if (intArchiveID == -1)
      cstmt2 = con.prepareCall("{call dbo.selProjectTractFunding(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}");
      else
      {
      cstmt2 = con.prepareCall("{call dbo.selProjectTractFundingFromArchive(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}");
      cstmt2.setInt("ArchiveID",intArchiveID);
      }
      cstmt2.setInt("ProjectID",intProjectID);
      cstmt2.setInt("CurrentProposedFundingFY", intCurrentProposedFundingFY);
      cstmt2.registerOutParameter("LastStatusCD", java.sql.Types.INTEGER);
      cstmt2.registerOutParameter("LastFundingFY", java.sql.Types.INTEGER);
      cstmt2.registerOutParameter("curFundingAmount", java.sql.Types.INTEGER);
      cstmt2.registerOutParameter("curCostShareAmount", java.sql.Types.INTEGER);
      cstmt2.registerOutParameter("curTotalFLPCost", java.sql.Types.INTEGER);
      cstmt2.registerOutParameter("curOtherFedAmount", java.sql.Types.INTEGER);
      cstmt2.registerOutParameter("curOtherFedCostShareAmount", java.sql.Types.INTEGER);
      cstmt2.registerOutParameter("curTotalCost", java.sql.Types.INTEGER);
      cstmt2.registerOutParameter("curAcre", java.sql.Types.INTEGER);
      cstmt2.registerOutParameter("TotalFundingAmount", java.sql.Types.INTEGER);
      cstmt2.registerOutParameter("TotalCostShareAmount", java.sql.Types.INTEGER);
      cstmt2.registerOutParameter("TotalFLPCost", java.sql.Types.INTEGER);
      cstmt2.registerOutParameter("TotalOtherFedAmount", java.sql.Types.INTEGER);
      cstmt2.registerOutParameter("TotalOtherFedCostShareAmount", java.sql.Types.INTEGER);
      cstmt2.registerOutParameter("TotalCost", java.sql.Types.INTEGER);
      cstmt2.registerOutParameter("TotalAcre", java.sql.Types.INTEGER);
      cstmt2.registerOutParameter("FundingAmountToDate", java.sql.Types.INTEGER);

      boolean bCstmt2Exe = cstmt2.execute();
      ResultSet rs2=null;
      //if (bCstmt2Exe == true)
      rs2 = cstmt2.getResultSet();


      Table tblTracts = new Table(new float[]{ 6,3,5,5,5,5 });
      tblTracts.setWidth(468f);
      tblTracts.setMarginBottom(12f);
      tblTracts.getAccessibilityProperties().addAttributes(new PdfStructureAttributes("Table").addTextAttribute("Summary","This table lists all tracts in the project and their size, cost, FLP funding, Cost Share and Status." ));

      float fltCellPaddingTop=0f;
      float fltCellPaddingRight=2f;
      float fltCellPaddingLeft=2f;
      float fltCellPaddingBottom=-1f;

      Cell c1 = new Cell().add(new Paragraph("Tract Name")).addStyle(styleTableHeader);
      c1.setTextAlignment(TextAlignment.LEFT);
      c1.setVerticalAlignment(VerticalAlignment.BOTTOM);
      c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
      tblTracts.addHeaderCell(c1);

      c1 = new Cell().add(new Paragraph("Size (ac)")).addStyle(styleTableHeader);
      c1.setTextAlignment(TextAlignment.CENTER);
      c1.setVerticalAlignment(VerticalAlignment.BOTTOM);
      c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
      tblTracts.addHeaderCell(c1);

      c1 = new Cell().add(new Paragraph("Tract Cost")).addStyle(styleTableHeader);
      c1.setTextAlignment(TextAlignment.CENTER);
      c1.setVerticalAlignment(VerticalAlignment.BOTTOM);
      c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
      tblTracts.addHeaderCell(c1);

      c1 = new Cell().add(new Paragraph("FLP Funding")).addStyle(styleTableHeader);
      c1.setTextAlignment(TextAlignment.CENTER);
      c1.setVerticalAlignment(VerticalAlignment.BOTTOM);
      c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
      tblTracts.addHeaderCell(c1);

      c1 = new Cell().add(new Paragraph("Non-Fed Cost Share")).addStyle(styleTableHeader);
      c1.setTextAlignment(TextAlignment.CENTER);
      c1.setVerticalAlignment(VerticalAlignment.BOTTOM);
      c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
      tblTracts.addHeaderCell(c1);

      c1 = new Cell().add(new Paragraph("Status")).addStyle(styleTableHeader);
      c1.setTextAlignment(TextAlignment.CENTER);
      c1.setVerticalAlignment(VerticalAlignment.BOTTOM);
      c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
      tblTracts.addHeaderCell(c1);


      while (rs2.next()){
      int intTractID = rs2.getInt("TractID");
      logger.info("nTractID: "+
      Integer.toString(intTractID));

      c1 = new Cell().add(new Paragraph(rs2.getString("TractName")).addStyle(styleTableCell));
      c1.setTextAlignment(TextAlignment.LEFT);
      c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
      tblTracts.addCell(c1);
      c1 = new Cell().add(new Paragraph(integerFormatter.format(rs2.getInt("Acre"))).addStyle(styleTableCell));
      c1.setTextAlignment(TextAlignment.RIGHT);
      c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
      tblTracts.addCell(c1);
      c1 = new Cell().add(new Paragraph(currencyFormatter.format(rs2.getInt("FLPCost"))).addStyle(styleTableCell));
      c1.setTextAlignment(TextAlignment.RIGHT);
      c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
      tblTracts.addCell(c1);
      c1 = new Cell().add(new Paragraph(currencyFormatter.format(rs2.getInt("FundingAmount"))).addStyle(styleTableCell));
      c1.setTextAlignment(TextAlignment.RIGHT);
      c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
      tblTracts.addCell(c1);
      c1 = new Cell().add(new Paragraph(currencyFormatter.format(rs2.getInt("CostShareAmount"))).addStyle(styleTableCell));
      c1.setTextAlignment(TextAlignment.RIGHT);
      c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
      tblTracts.addCell(c1);
      c1 = new Cell().add(new Paragraph(rs2.getString("DisplayStatusFY")).addStyle(styleTableCell));
      c1.setTextAlignment(TextAlignment.CENTER);
      c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
      tblTracts.addCell(c1);
      }


      int LastFundingFY = cstmt2.getInt("LastFundingFY");
      int curFundingAmount = cstmt2.getInt("curFundingAmount");
      int curCostShareAmount = cstmt2.getInt("curCostShareAmount");
      int curTotalFLPCost = cstmt2.getInt("curTotalFLPCost");
      int curAcre = cstmt2.getInt("curAcre");
      int TotalFLPCost = cstmt2.getInt("TotalFLPCost");
      int TotalAcre = cstmt2.getInt("TotalAcre");
      int FundingAmountToDate = cstmt2.getInt("FundingAmountToDate");

      Table tblFunding = new Table(new float[]{120,60});
      float fltTableFundingCellHeight = 12f;
      tblFunding.setWidth(270F);
      tblFunding.setMarginBottom(16f);
      tblFunding.getAccessibilityProperties().addAttributes(new PdfStructureAttributes("Table").addTextAttribute("Summary","This table provides an overview of the Forest Legacy Program funding history for this project." ));

      c1 = new Cell().add(new Paragraph("FY " + LastFundingFY + " Forest Legacy Program Funding").addStyle(styleTableHeader));
      c1.setTextAlignment(TextAlignment.RIGHT);
      c1.setBorder(Border.NO_BORDER);
      c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
      c1.setHeight(fltTableFundingCellHeight);
      c1.getAccessibilityProperties().setRole(StandardRoles.TH);
      tblFunding.addCell(c1);
      c1 = new Cell().add(new Paragraph(currencyFormatter.format(curFundingAmount)).addStyle(styleTableHeader));
      c1.setTextAlignment(TextAlignment.RIGHT);
      c1.setBorder(Border.NO_BORDER);
      c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
      c1.setHeight(fltTableFundingCellHeight);
      tblFunding.addCell(c1);

      c1 = new Cell().add(new Paragraph("FY " + LastFundingFY + " Non-Federal Cost Share").addStyle(styleTableHeader));
      c1.setTextAlignment(TextAlignment.RIGHT);
      c1.setBorder(Border.NO_BORDER);
      c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
      c1.setHeight(fltTableFundingCellHeight);
      c1.getAccessibilityProperties().setRole(StandardRoles.TH);
      tblFunding.addCell(c1);
      c1 = new Cell().add(new Paragraph(currencyFormatter.format(curCostShareAmount)).addStyle(styleTableHeader));
      c1.setTextAlignment(TextAlignment.RIGHT);
      c1.setBorder(Border.NO_BORDER);
      c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
      c1.setHeight(fltTableFundingCellHeight);
      tblFunding.addCell(c1);

      c1 = new Cell().add(new Paragraph("FY " + LastFundingFY + " Project Costs").addStyle(styleTableHeader));
      c1.setTextAlignment(TextAlignment.RIGHT);
      c1.setBorder(Border.NO_BORDER);
      c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
      c1.setHeight(fltTableFundingCellHeight);
      c1.getAccessibilityProperties().setRole(StandardRoles.TH);
      tblFunding.addCell(c1);
      c1 = new Cell().add(new Paragraph(currencyFormatter.format(curTotalFLPCost)).addStyle(styleTableHeader));
      c1.setTextAlignment(TextAlignment.RIGHT);
      c1.setBorder(Border.NO_BORDER);
      c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
      c1.setHeight(fltTableFundingCellHeight);
      tblFunding.addCell(c1);


      c1 = new Cell().add(new Paragraph("FY " + LastFundingFY + " Project Acres").addStyle(styleTableHeader));
      c1.setTextAlignment(TextAlignment.RIGHT);
      c1.setBorder(Border.NO_BORDER);
      c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom + 10f, fltCellPaddingLeft);
      c1.setHeight(fltTableFundingCellHeight);
      c1.getAccessibilityProperties().setRole(StandardRoles.TH);
      tblFunding.addCell(c1);
      c1 = new Cell().add(new Paragraph(integerFormatter.format(curAcre)).addStyle(styleTableHeader));
      c1.setTextAlignment(TextAlignment.RIGHT);
      c1.setBorder(Border.NO_BORDER);
      c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom + 10f, fltCellPaddingLeft);
      c1.setHeight(fltTableFundingCellHeight);
      tblFunding.addCell(c1);

      c1 = new Cell().add(new Paragraph("Forest Legacy Funding To Date").addStyle(styleTableHeader));
      c1.setTextAlignment(TextAlignment.RIGHT);
      c1.setBorder(Border.NO_BORDER);
      c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
      c1.setHeight(fltTableFundingCellHeight);
      c1.getAccessibilityProperties().setRole(StandardRoles.TH);
      tblFunding.addCell(c1);
      c1 = new Cell().add(new Paragraph(currencyFormatter.format(FundingAmountToDate)).addStyle(styleTableHeader));
      c1.setTextAlignment(TextAlignment.RIGHT);
      c1.setBorder(Border.NO_BORDER);
      c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
      c1.setHeight(fltTableFundingCellHeight);
      tblFunding.addCell(c1);

      c1 = new Cell().add(new Paragraph("Total Project Costs").addStyle(styleTableHeader));
      c1.setTextAlignment(TextAlignment.RIGHT);
      c1.setBorder(Border.NO_BORDER);
      c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
      c1.setHeight(fltTableFundingCellHeight);
      c1.getAccessibilityProperties().setRole(StandardRoles.TH);
      tblFunding.addCell(c1);
      c1 = new Cell().add(new Paragraph(currencyFormatter.format(TotalFLPCost)).addStyle(styleTableHeader));
      c1.setTextAlignment(TextAlignment.RIGHT);
      c1.setBorder(Border.NO_BORDER);
      c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
      c1.setHeight(fltTableFundingCellHeight);
      tblFunding.addCell(c1);

      c1 = new Cell().add(new Paragraph("Total Project Acres").addStyle(styleTableHeader));
      c1.setTextAlignment(TextAlignment.RIGHT);
      c1.setBorder(Border.NO_BORDER);
      c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
      c1.setHeight(fltTableFundingCellHeight);
      c1.getAccessibilityProperties().setRole(StandardRoles.TH);
      tblFunding.addCell(c1);
      c1 = new Cell().add(new Paragraph(integerFormatter.format(TotalAcre)).addStyle(styleTableHeader));
      c1.setTextAlignment(TextAlignment.RIGHT);
      c1.setBorder(Border.NO_BORDER);
      c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
      c1.setHeight(fltTableFundingCellHeight);
      tblFunding.addCell(c1);

      cstmt2.close();


      Here is the Stored Procedure that gives error. (Please note comment of sql query that if converted to static table, resolves the error!):



      /****** Object: StoredProcedure [dbo].[selProjectTractFunding] Script Date: 2/20/2019 3:48:22 PM ******/
      SET ANSI_NULLS ON
      GO
      SET QUOTED_IDENTIFIER ON
      GO
      */



      CREATE PROCEDURE [dbo].[selProjectTractFunding] ( @ProjectID int,
      @CurrentProposedFundingFY int, @LastStatusCD int out, @LastFundingFY int out,
      @curFundingAmount int out, @curCostShareAmount int out,
      @curTotalFLPCost int out, @curOtherFedAmount int out,
      @curOtherFedCostShareAmount int out, @curTotalCost int out,
      @curAcre int out, @TotalFundingAmount int out,
      @TotalCostShareAmount int out, @TotalFLPCost int out,
      @TotalOtherFedAmount int out, @TotalOtherFedCostShareAmount int out,
      @TotalCost int out, @TotalAcre int out,
      @FundingAmountToDate int out )
      AS
      declare @RC int



      /***  All works FINE if I convert this first query to a static table TEMP1 and replace it with "select * from temp1".  Does not work from temporary table #temp1 as coded here.  ***/
      select pt.ProjectID
      ,t.TractID
      ,t.TractName
      ,t.PurchaseTypeCD
      ,cast(isnull(t.Acre,0) as int) as Acre
      ,cast(isnull(t.FundingAmount,0) as bigint) as FundingAmount
      ,cast(isnull(costshare.CostShareAmount,0) as bigint) as CostShareAmount
      ,cast((isnull(t.FundingAmount,0) + isnull(costshare.CostShareAmount,0)) as bigint) as FLPCost
      ,cast(isnull(ofed.OtherFedAmount,0) as bigint) as OtherFedAmount
      ,cast(isnull(ofed.OtherFedCostShareAmount,0) as bigint) as OtherFedCostShareAmount
      ,cast((isnull(t.FundingAmount,0) + isnull(costshare.CostShareAmount,0) + isnull(ofed.OtherFedAmount,0) + isnull(ofed.OtherFedCostShareAmount,0)) as bigint) as TotalCost
      ,cast(dbo.getFY(CompleteDate) as int) as CompleteFY
      ,ts.StatusCD
      ,s.Status
      ,s.DisplayStatus
      ,cast(case when t.CompleteDate is null then s.DisplayStatus + ' ' + cast(ts.FundingFY as varchar) else s.DisplayStatus + ' ' + cast(dbo.getFY(t.CompleteDate) as varchar) end as varchar) as DisplayStatusFY
      ,ts.FundingFY
      ,ts.CreatedOn
      into #temp1
      from (select TractID, max(CreatedOn) as CreatedOn from dbo.TractStatus group by TractID ) cs
      inner join dbo.TractStatus ts on cs.TractID = ts.TractID and cs.CreatedOn = ts.CreatedOn
      inner join dbo.Tract t on ts.TractID = t.TractID
      inner join dbo.ProjectTract pt on t.TractID = pt.TractID
      left outer join (select TractID, Sum(OtherFedAmount) as OtherFedAmount, sum(OtherFedCostShareAmount) as OtherFedCostShareAmount from dbo.OtherFederal group by TractID ) ofed on ofed.TractID = t.TractID
      left outer join (select TractID, sum(CostShareAmount) as CostShareAmount from dbo.CostShare group by TractID) costshare on costshare.TractID = t.TractID
      inner join dbo._refStatus s on ts.StatusCD = s.StatusCD
      where pt.ProjectID = @ProjectID
      and ts.StatusCD <> 120

      set @RC = @@RowCount

      -- Return recorset of tract details
      select * from #temp1 t
      order by t.TractName

      -- Get Last or Latest Status (other than closed/complete) for latest FundingFY for Project
      select top 1 @LastStatusCD = StatusCD
      ,@LastFundingFY = isnull(FundingFY,0)
      from #temp1
      where not statuscd in (35,100,110,120) and FundingFY <= @CurrentProposedFundingFY
      order by FundingFY desc, StatusCD desc

      -- If LastStatusCD is null then set to 100
      if @LastStatusCD is null
      select top 1 @LastStatusCD = StatusCD
      ,@LastFundingFY = FundingFY
      from #temp1
      where statuscd in (100,110) and FundingFY <= @CurrentProposedFundingFY
      order by FundingFY desc, StatusCD desc

      -- Return Subtotals for Current Status and Year
      select @curFundingAmount = sum(FundingAmount)
      ,@curCostShareAmount = sum(CostShareAmount)
      ,@curTotalFLPCost = sum(FLPCost)
      ,@curOtherFedAmount = sum(OtherFedAmount)
      ,@curOtherFedCostShareAmount = sum(OtherFedCostShareAmount)
      ,@curTotalCost = sum(TotalCost)
      ,@curAcre = sum(Acre)
      from #temp1
      where FundingFY = @LastFundingFY and StatusCD >= @LastStatusCD

      -- Return Project Totals
      select @TotalFundingAmount = sum(FundingAmount)
      ,@TotalCostShareAmount = sum(CostShareAmount)
      ,@TotalFLPCost = sum(FLPCost)
      ,@TotalOtherFedAmount = sum(OtherFedAmount)
      ,@TotalOtherFedCostShareAmount = sum(OtherFedCostShareAmount)
      ,@TotalCost = sum(TotalCost)
      ,@TotalAcre = sum(Acre)
      from #temp1

      -- Return FLP Funding Amount To Date
      select
      @FundingAmountToDate = sum(FundingAmount)
      from #temp1
      where StatusCD >= 80 and StatusCD < 120

      -- Check for only dropped tracts
      if @RC = 0 -- this statement is true only if the first query returned no records
      begin
      select @LastFundingFY = max(ts.FundingFY)
      from (select TractID, max(CreatedOn) as CreatedOn from dbo.TractStatus group by TractID ) cs
      inner join dbo.TractStatus ts on cs.TractID = ts.TractID and cs.CreatedOn = ts.CreatedOn
      inner join dbo.ProjectTract pt on ts.TractID = pt.TractID
      where pt.ProjectID = @ProjectID
      end

      return @LastStatusCD;
      return @LastFundingFY;
      return @curFundingAmount;
      return @curCostShareAmount;
      return @curTotalFLPCost;
      return @curOtherFedAmount;
      return @curOtherFedCostShareAmount;
      return @curTotalCost;
      return @curAcre;
      return @TotalFundingAmount;
      return @TotalCostShareAmount;
      return @TotalFLPCost;
      return @TotalOtherFedAmount;
      return @TotalOtherFedCostShareAmount;
      return @TotalCost;
      return @TotalAcre;
      return @FundingAmountToDate;


      drop table #temp1;






      sql-server-2012 jdbc





      share







      New contributor




      BBSings is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.










      share







      New contributor




      BBSings is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      share



      share






      New contributor




      BBSings is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 6 mins ago









      BBSingsBBSings

      1




      1




      New contributor




      BBSings is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      BBSings is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      BBSings is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          0






          active

          oldest

          votes











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "182"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });






          BBSings is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f230440%2fsql-jdbc-upgrade-from-v6-0-to-v7-2-causes-java-lang-nullpointerexception-in-some%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          BBSings is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          BBSings is a new contributor. Be nice, and check out our Code of Conduct.













          BBSings is a new contributor. Be nice, and check out our Code of Conduct.












          BBSings is a new contributor. Be nice, and check out our Code of Conduct.
















          Thanks for contributing an answer to Database Administrators Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f230440%2fsql-jdbc-upgrade-from-v6-0-to-v7-2-causes-java-lang-nullpointerexception-in-some%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Armoriale delle famiglie italiane (Car) Indice Armi | Bibliografia | Menu di navigazioneBlasone...

          Why does this relation fail symmetry and transitivity properties?Properties of Relations. Reflexive,...

          why typing a variable (or expression) prints the value to stdout?Calling a function of a module by using its...