如何通过JDBC在SQL Server中设置context_info?

时间:2019-06-13 20:28:14

标签: jdbc

我想将Sql Server与JDBC连接,并通过sql语句(如“ set context_info 123”)设置当前会话的上下文信息。我需要PreparedStatement还是CallableStatement?

我尝试了两个接口,但似乎找不到返回结果的方法。

例如,使用CallableStatement的代码将与此类似:

val setContextQuery = s"set context_info 123"
var callabelStmt = l_conn.prepareCall(setContextQuery)
callabelStmt.execute

// test if the info is set:
callabelStmt = l_conn.prepareCall("SELECT CONTEXT_INFO()")
var rs = callabelStmt.executeQuery
println(s"Current session has context info: ${rs.getInt(1)}")

0 个答案:

没有答案