So i have a method
and i have a stored procedure in sql....
and i have an sql exception error
i have no idea whats wrong. It seams to think that a null is present...... but i thought i fixxed that in teh decleration of @maxVessels
Code:
public String vesselLookup(String VesselName){
String vessellookupnumber = "";
CallableStatement proc_stmt = null;
try{
proc_stmt = Global.con.prepareCall("{call sp_Vessellookup(?, ?)}");
proc_stmt.setString(1, VesselName);
proc_stmt.setInt(2, 0);
} catch (SQLException e1){
e1.printStackTrace();
}
try {
proc_stmt.registerOutParameter(2, Types.INTEGER);
proc_stmt.execute();
vessellookupnumber = Integer.toString(proc_stmt.getInt(2));
proc_stmt.close();
} catch (SQLException s) {
System.err.println(s);
}
return vessellookupnumber;
}
and i have a stored procedure in sql....
Code:
USE [DEV_ACIMonitoring]
GO
/****** Object: StoredProcedure [dbo].[sp_Vessellookup] Script Date: 07/12/2012 11:23:35 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <XXXXXXXXXXX>
-- Create date: <2012-07-12>
-- Description: <Returns the value of the stored name,
-- If the name isnt in there, it Inserts a new row>
-- =============================================
ALTER PROCEDURE [dbo].[sp_Vessellookup](
@vesselinput varchar(200),
@i int OUTPUT
)
AS
BEGIN
DECLARE @vesselNumber int
SET @vesselNumber = (SELECT vesselNumber FROM tblVesselLookup WHERE vessel = @vesselinput)
IF @vesselNumber IS NULL
BEGIN
DECLARE @maxVessels INT SET @maxVessels = (SELECT (MAX(vesselNumber) + 1) FROM tblVesselLookup)
IF @maxVessels = NULL SET @maxVessels = 1
INSERT INTO tblVesselLookup VALUES (@maxVessels, @vesselinput)
SET @i = @maxVessels
END
ELSE
BEGIN
SET @i = @vesselNumber
END
RETURN @i
END
and i have an sql exception error
Code:
com.microsoft.sqlserver.jdbc.SQLServerException: Cannot insert the value NULL into column 'vesselNumber', table 'DEV_ACIMonitoring.dbo.tblVesselLookup'; column does not allow nulls. INSERT fails.
i have no idea whats wrong. It seams to think that a null is present...... but i thought i fixxed that in teh decleration of @maxVessels





