[英]How to get OUTPUT parameter of stored procedure sp_setapprole in SQLServer
I'm using the following JDBC driver (the one from Microsoft): http://msdn.microsoft.com/en-us/sqlserver/aa937724.aspx . 我正在使用以下JDBC驱动程序(来自Microsoft的一种): http : //msdn.microsoft.com/zh-cn/sqlserver/aa937724.aspx 。
I want to retrieve the OUTPUT parameter (@cookie) of the stored procedure sp_setapprole
. 我想检索存储过程
sp_setapprole
的OUTPUT参数(@cookie)。 I can call the procedure fine like this, but I can't figure out how to retrieve the OUTPUT parameter. 我可以像这样很好地调用过程,但是我不知道如何检索OUTPUT参数。
statement = connection.createStatement();
statement.execute("EXEC sp_setapprole '" + applicationRoleName + "', '" + applicationRolePassword + "'");
I tried with a PreparedStatement and a CallableStatement and I always get the following exception: Stored procedure 'sys.sp_setapprole' can only be executed at the ad hoc level.
我尝试了PreparedStatement和CallableStatement,但始终收到以下异常:
Stored procedure 'sys.sp_setapprole' can only be executed at the ad hoc level.
. 。 I found this post: https://stackoverflow.com/a/6944693/1362049 , but I don't like the solution (use another JDBC driver).
我找到了这篇文章: https : //stackoverflow.com/a/6944693/1362049 ,但是我不喜欢该解决方案(使用另一个JDBC驱动程序)。
So my question: how to get OUTPUT parameter from stored procedure sp_setapprole
in SQLServer using a Statement
. 所以我的问题是:如何使用
Statement
从SQLServer中的存储过程sp_setapprole
获取OUTPUT参数。
I think this will help. 我认为这会有所帮助。 I am not a big java program but lived with ODBC for years.
我不是一个大型的Java程序,但是与ODBC一起生活了很多年。
http://www.tutorialspoint.com/jdbc/jdbc-statements.htm http://www.tutorialspoint.com/jdbc/jdbc-statements.htm
Look at the callable statement. 查看可调用的语句。 You need to define the in/out, or inout parameters.
您需要定义in / out或inout参数。 Execute the SP and read the output.
执行SP并读取输出。
In C#, it is just looking at the parameter such as below give you the value. 在C#中,它只是在查看诸如下面的参数这样的值。 But the idea of making a connection, binding parameters, making the call and reading the output are the same.
但是建立连接,绑定参数,进行调用以及读取输出的想法是相同的。
my_Cmd.Parameters["@PageCount"].Value.ToString(); my_Cmd.Parameters [“ @ PageCount”]。Value.ToString();
Here is a article from MSDN in C++. 这是C ++中MSDN的文章。
http://technet.microsoft.com/en-us/library/ms403283.aspx http://technet.microsoft.com/zh-CN/library/ms403283.aspx
Same idea, bind parameters, make the call, read the output using [SQLExecDirect] 相同的想法,绑定参数,进行调用,并使用[SQLExecDirect]读取输出
Give me a holler if you do not get it. 如果你不明白,请给我一个叫声。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.