我想将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)}")