Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › [SQL and JAVA] Having some trouble
New Posts  All Forums:Forum Nav:

[SQL and JAVA] Having some trouble

post #1 of 3
Thread Starter 
So i have a method
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
post #2 of 3
Thread Starter 
ps i found the problem..... im my sql bit i put = Null not is null XD
post #3 of 3
I am just now learning this sql server syntax for stored procedures so maybe they are more lax, but don't you technically need...

INSERT INTO tblVesselLookup (maxcolumn, inputcolumn) VALUES (@maxVessels, @vesselinput)

EDIT: Damn, guess I took awhile to reply.
Croissant
(13 items)
 
  
CPUMotherboardGraphicsRAM
2600k Asus P67 Deluxe Dual 6970 2x4 gigs 
Hard DriveMonitorPowerCase
WD 500 gig 7200 RPM Dual ASUS 24" Antec 850 Rosewill Thor 
  hide details  
Reply
Croissant
(13 items)
 
  
CPUMotherboardGraphicsRAM
2600k Asus P67 Deluxe Dual 6970 2x4 gigs 
Hard DriveMonitorPowerCase
WD 500 gig 7200 RPM Dual ASUS 24" Antec 850 Rosewill Thor 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › [SQL and JAVA] Having some trouble