MS SQL Stored Procedure and the JDBC

I have been assigned to create a JSP that uses an SQL Stored Procedure that returns an output parameter. Normally, this is no problem. However, this particular store procedure calls other stored procedures and exchanges data between them. This same stored procedure works in an ASP But not my JSP. I think that this is due to the limitations of the JDBC. Is there any way that a call to such a stored procedure can function properly via the JDBC. I might also add that I am using the JDBC-ODBC bridge and JRun 2.3.3. Any help that can be provided will be more than appreciated.

Thank you in advance.

jamochacoder

[638 byte] By [jamochacoder] at [2007-9-26 2:26:59]
# 1

> This same stored procedure works in an ASP But not my JSP.

What happens? Exception? Which? Where?

> I think that this is due to the limitations of the

> JDBC. Is there any way that a call to such a stored

> procedure can function properly via the JDBC.

Have not yet heard about such a limitatation.

Why should it be of any interest for JDBC (or ODBC), what the stored proc does inside?

If you can execute any stored proc with JDBC-ODBC, I don't believe that your problem lies there.

I'd suggest to look inside the stored proc and its sub-procs.

There may be internal locks, that can be influenced by the used isloation level (are you sure you use the same like in ASP - evtl. something is set implicitely?) and also the time behaviour.

Another possibility: errors in your code?

If you want, post the relevant part. This would help us to help you, I guess.

Hartmut at 2007-6-29 9:40:35 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2

In response to your submission, and thanks, by the way, here is a snip of my code and the s.p. :

<%!

public String getLCN()

{

String sDriverProtocol = "jdbc:odbc:xxxx";

String sDBUserID = "xxxx";

String sDBPassword = "xxxx";

Connection con;

CallableStatement stmt = null;

ResultSet rs = null;

int ibalance = 0;

ibalance = Integer.parseInt(balance);

try

{

new sun.jdbc.odbc.JdbcOdbcDriver();

con = DriverManager.getConnection(sDriverProtocol, sDBUserID, sDBPassword);

stmt = con.prepareCall("{call usp_LeaveIndocVal(?,?,?,?,?,?,?,?,?)}");

stmt.setString(1, ssn);

stmt.setString(2, sDate);

stmt.setString(3, sTime);

stmt.setString(4, eDate);

stmt.setString(5, eTime);

stmt.setString(6, type);

stmt.setString(7, user);

stmt.setInt(8, ibalance);

stmt.registerOutParameter(9, java.sql.Types.VARCHAR);

stmt.execute();

rtrvr = stmt.getString(9);

rs.close();

stmt.close();

con.close();

}

catch (Exception err)

{

System.err.println("getLCN method error: " + err.toString());

}

return rtrvr;

}

%>

And here is the sp (it's pretty big):

CREATE PROCEDURE dbo.usp_LeaveIndocVal

@sSsnchar(9),

@dLvStartdatetime,

@sStartTimevarchar(4),

@dLvEnddatetime,

@sEndTimevarchar(4),

@sLvTypevarchar(15),

@sUserIdvarchar(25),

@iLvBalanceint,

@sLcnvarchar(8)OUTPUT

AS

DECLARE @sEventIdvarchar(15),

@iEventIdint,

@iCourseIdint,

@dEvStartdatetime,

@dEvEnddatetime,

@dCmdIndocdatetime,

@iNewEventIdint,

@dNewStartDatedatetime

DECLARE crList CURSOR FOR

SELECT te.trngeventid, te.courseid, te.startdate, te.enddate, id.cmdindoc

FROM etjroster tr

LEFT JOIN IndocDates id ON id.ssn = tr.ssn

LEFT JOIN etjtrngevent te ON te.trngeventid = tr.trngeventid

WHERE tr.ssn = @sSsn

AND (te.courseid = 1 OR te.courseid = 2)

AND ((@dLvStart >= startdate AND @dLvStart <= enddate)

OR (@dLvEnd >= startdate AND @dLvStart <= enddate))

OPEN crList

/* Get the first row from the cursor */

FETCH NEXT FROM crList INTO @iEventId, @iCourseId, @dEvStart, @dEvEnd, @dCmdIndoc

/* Close the cursor & Deallocate memory */

CLOSE crList

DEALLOCATE crList

IF @iEventId IS NULL

BEGIN

/* If we are here, then there is no conflict with Indoc.

Get the leave control number, insert record in leave log

and update muster control table

*/

EXEC usp_LeaveCntrlNum @sLcn OUTPUT

EXEC usp_LeaveLogInsert @sLcn, @dLvStart,

@sStartTime, @dLvEnd, @sEndTime,

@sLvType, @sSsn

EXEC usp_LeaveMusterUpd@sLvType, @sSsn, @dLvStart,

@dLvEnd, @sLcn, @iLvBalance

END

ELSE

BEGIN

/* If we are here, then there is a conflict with Indoc.

Get the scheduled Indoc events and find one that is

less than 13 months after the indiv inital command indoc.

Get the leave control number, insert record in leave log

and muster control

*/

DECLARE crNewList CURSOR FOR

SELECT te.trngeventid, te.StartDate

FROM etjtrngevent te

WHERE te.courseid = @iCourseId

AND (te.startdate > @dEvStart AND te.startdate > @dLvEnd)

AND seatsUsed < seatsAvail

OPEN crNewList

FETCH NEXT FROM crNewList INTO @iNewEventId, @dNewStartDate

WHILE @@FETCH_STATUS = 0

BEGIN

DECLARE @iCmdMonint,

@iEventMonint

SELECT @iCmdMon = DATEPART(mm,@dCmdIndoc)

SELECT @iEventMon = DATEPART(mm, @dNewStartDate)

IF @iCmdMon - @iEventMon > 0

BEGIN

EXEC usp_LeaveCntrlNum @sLcn OUTPUT

EXEC usp_LeaveLogInsert @sLcn, @dLvStart,

@sStartTime, @dLvEnd, @sEndTime,

@sLvType, @sSsn

EXEC usp_LeaveMusterUpd@sLvType, @sSsn, @dLvStart,

@dLvEnd, @sLcn, @iLvBalance

BREAK

END

ELSE

BEGIN

FETCH NEXT FROM crNewList INTO @iNewEventId, @dNewStartDate

END

END

CLOSE crNewList

DEALLOCATE crNewList

/* If the leave control number equals 0, then there was a

conflict. Emergency leaves take precedent, so get the

leave control number, insert record in leave log

and muster control or notify the Indoc Coordinator

*/

IF @sLcn = '0'

BEGIN

IF @sLvType = 'Emergency'

BEGIN

EXEC usp_LeaveCntrlNum @sLcn OUTPUT

EXEC usp_LeaveLogInsert @sLcn, @dLvStart,

@sStartTime, @dLvEnd, @sEndTime,

@sLvType, @sSsn

EXEC usp_LeaveMusterUpd@sLvType, @sSsn, @dLvStart,

@dLvEnd, @sLcn, @iLvBalance

END

/*

ELSE

EXEC usp_IndocCoordinatorEMail @sSsn

*/

END

END

jamochacoderX at 2007-6-29 9:40:35 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3

I think that I found the problem. I added :

rs = stmt.getResultSet();

while(rs.next())

{

}

which cleared out anything that may have been sitting there. And now I get the desired result. Thanks for the help. However, if upon viewing my code you find something that may be beneficial to me, by all means feel free to point it out. Thanks

jamochacoder

jamochacoderX at 2007-6-29 9:40:35 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...