I would like to call this stored procedure with jdbc:
sp_msforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT all"
JDBC thinks the ? is a placeholder for an argument. In fact it is used by the SP to put in the table name. How can I call the stored procedure? I tried this:
CallableStatement call = jdbcConnection.prepareCall("call sp_msforeachtable(?)");
call.setString(1, "\"ALTER TABLE ? NOCHECK CONSTRAINT all\"");
call.executeUpdate();
and I get a syntax error near ‘@P0’. I guess ‘@P0’ is the ?. How can I call this SP? I am using SQL Server 2008 BTW.
You say that the
?is supposed to be for a table name, so you need to provide an actual table name before callingStatement.executeUpdate(). At that point the JDBC driver will tell the database to actually run the statement, so obviously all parameters need to be bound.Maybe you meant to write this:
or maybe you meant to write this:
I’m not sure exactly what
sp_msforeachtable()is supposed to do, but I do know that you have to provide values for all parameters before callingexecuteUpdate()