我可以设置的Microsoft SQL Server 2012个的选项,如ARITHABORT
编程方式使用Microsoft JDBC驱动程序4.0(远程)Java客户端? 我注意到statement.execute("SET ARITHABORT ON")
返回false
和预期的效果似乎缺少,因此这个问题。
Answer 1:
我可以设置的Microsoft SQL Server 2012个的选项,如ARITHABORT编程方式使用Microsoft JDBC驱动程序4.0(远程)Java客户端?
这当然会出现如此。 编码
package com.example.sqlservertest;
import java.sql.*;
public class SqlServerTestMain {
public static void main(String[] args) {
String connectionUrl = "jdbc:sqlserver://localhost:52865;"
+ "databaseName=myDb;" + "integratedSecurity=true";
try (Connection con = DriverManager.getConnection(connectionUrl)) {
System.out.println("Connection established.");
try (Statement stmt = con.createStatement()) {
try (ResultSet rs = stmt.executeQuery("SELECT CONVERT(INT, SESSIONPROPERTY('ARITHABORT'))")) {
rs.next();
System.out.println(String.format(
"SESSIONPROPERTY('ARITHABORT') is %d",
rs.getInt(1)));
}
String sql = "SET ARITHABORT ON";
System.out.println(sql);
stmt.execute(sql);
try (ResultSet rs = stmt.executeQuery("SELECT CONVERT(INT, SESSIONPROPERTY('ARITHABORT'))")) {
rs.next();
System.out.println(String.format(
"SESSIONPROPERTY('ARITHABORT') is %d",
rs.getInt(1)));
}
sql = "SET ARITHABORT OFF";
System.out.println(sql);
stmt.execute(sql);
try (ResultSet rs = stmt.executeQuery("SELECT CONVERT(INT, SESSIONPROPERTY('ARITHABORT'))")) {
rs.next();
System.out.println(String.format(
"SESSIONPROPERTY('ARITHABORT') is %d",
rs.getInt(1)));
}
}
} catch (Exception e) {
e.printStackTrace(System.out);
}
}
}
回报
Connection established.
SESSIONPROPERTY('ARITHABORT') is 0
SET ARITHABORT ON
SESSIONPROPERTY('ARITHABORT') is 1
SET ARITHABORT OFF
SESSIONPROPERTY('ARITHABORT') is 0
该ARITHABORT国家应继续有效的连接的生命,除非一些其他的代码改变它。
文章来源: Can JDBC client execute SET ARITHABORT ON on Microsoft SQL Server 2012?