I am having a problem with calling a stored procedure. I have
replicated the problem with multiple JDBC drivers so it doesn't seem to
be driver related. The stored procedure works when I execute in SQL
Enterprise Manager so it isn't the SQL Manager. The code hasn't changed
and it was working at one time so I need help!
I am calling a simple stored procedure that either inserts or updates a
record into a single table and returns the ID for the record. The
stored procedure definition is as follows:
CREATE PROCEDURE dbo.updateDistrictFiles
@brochureId int,
@districtId int,
@contactTypeId int,
@fileDesc varchar(50),
@filePath varchar(100),
@brochureIdOut int OUTPUT
....
The java code invoking the SP is as follows:
CallableStatement c = connection. prepareCall("? = call
updateDistrictFiles(?, ?, ?, ?, ?, ?)";
int index = 1;
cstmt.setInt(index++, getBrochureId());
cstmt.setInt(index++, getDistrictId());
cstmt.setInt(index++, getContactTypeId());
cstmt.setString(index++, getBrochureDescription());
cstmt.setString(index++, getBrochureLocation());
cstmt.registerOutParameter(index, Types.NUMERIC); // tried INTEGER too
recordCount = cstmt.executeUpdate();
newBrochureId = cstmt.getInt(index);
The "executeUpdate" throws the Java Exception with the message:
[Microsoft][SQLServer 2000 Driver for JDBC]Invalid parameter binding(s).
Partial stack trace below.
Any help would be GREATLY appreciated!
TIA
Earl
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for
JDBC]Invalid parameter binding(s).
[11/15/04 17:55:53:066 CST] 30e29198 SystemErr R at
com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
[11/15/04 17:55:53:066 CST] 30e29198 SystemErr R at
com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
[11/15/04 17:55:53:066 CST] 30e29198 SystemErr R at
com.microsoft.jdbc.base.BasePreparedStatement.validateParameters(Unknown
Source)
[11/15/04 17:55:53:066 CST] 30e29198 SystemErr R at
com.microsoft.jdbc.base.BasePreparedStatement.validateParameters(Unknown
Source)
[11/15/04 17:55:53:086 CST] 30e29198 SystemErr R at
com.microsoft.jdbc.base.BasePreparedStatement.preImplExecute(Unknown Source)
[11/15/04 17:55:53:086 CST] 30e29198 SystemErr R at
com.microsoft.jdbc.base.BaseStatement.commonExecute(Unknown Source)
[11/15/04 17:55:53:086 CST] 30e29198 SystemErr R at
com.microsoft.jdbc.base.BaseStatement.executeUpdateInternal(Unknown Source)
[11/15/04 17:55:53:086 CST] 30e29198 SystemErr R at
com.microsoft.jdbc.base.BasePreparedStatement.executeUpdate(Unknown Source)
[11/15/04 17:55:53:096 CST] 30e29198 SystemErr R at
com.microsoft.jdbcx.base.BasePreparedStatementWrapper.executeUpdate(Unknown
Source)
[11/15/04 17:55:53:096 CST] 30e29198 SystemErr R at
com.ibm.ws.rsadapter.jdbc.WSJdbcPreparedStatement.executeUpdate(WSJdbcPreparedStatement.java:555)
[11/15/04 17:55:53:096 CST] 30e29198 SystemErr R at
org.frb.chi.electronic.Brochure.update(Brochure.java:494)
"Earl Hokens" wrote...
>I am having a problem with calling a stored procedure.
> CREATE PROCEDURE dbo.updateDistrictFiles
> @brochureId int,
[quoted text clipped - 4 lines]
> @brochureIdOut int OUTPUT
> ....
Looks like SQL Server?
I'm not quite familiar with the creation of stored procedures in SQL Server,
but I can count to 6 arguments.
> The java code invoking the SP is as follows:
>
> CallableStatement c = connection.
> prepareCall("? = call updateDistrictFiles(?, ?, ?, ?, ?, ?)";
...but here I find 7 question marks...
Even the first one counts, so my guess is you could just try to change it
to:
CallableStatement c =
connection.prepareCall
("{call updateDistrictFiles(?, ?, ?, ?, ?, ?)}";
// Bjorn A
Earl Hokens - 16 Nov 2004 15:10 GMT
Thanks Bjorn, that did the trick. Thanks for the extra set of eyes.
I'm still a bit puzzled though, I know this code was working before as
it successfully made it through test and QA and it wouldn't have made it
without being able to insert records. So, something must've changed
either in the DB, appserver, or driver. All the proper admins tell me
nothing's changed. I'll chalk this one up to one of the great mysteries
of computer development.
I had also tried ? = proc_name(?, ?, ?, ?, ?) and proc_name(?, ?, ?, ?,
?, ?) as you suggested but they originally didn't work. When you posted
your solution I looked a little closer and noticed the {} and that did
the trick. Interesting.
Thanks again.
> "Earl Hokens" wrote...
>
[quoted text clipped - 29 lines]
>
> // Bjorn A