无法在 SQL Server 2019 中使用 Java Double.MIN_VALUE 4.9E-324 作为浮点文字
Can't use Java Double.MIN_VALUE 4.9E-324 as a floating point literal in SQL Server 2019
运行 以下 JDBC 代码与 SQL 服务器:
try (PreparedStatement s = connection.prepareStatement("select 4.9E-324, ?")) {
s.setDouble(1, 4.9E-324);
try (ResultSet rs = s.executeQuery()) {
while (rs.next()) {
System.out.println(rs.getDouble(1));
System.out.println(rs.getDouble(2));
}
}
}
结果是:
0.0
4.9E-324
因此,虽然绑定值被正确回显,但文字却没有。这怎么解释呢? I've noticed in the docs.
Any float value less than 5E-18 (when set using either the scientific notation of 5E-18 or the decimal notation of 0.0000000000000000050000000000000005) rounds down to 0. This is no longer a restriction as of SQL Server 2016 (13.x).
但我使用的是 SQL Server 2019
select @@version
产量:
Microsoft SQL Server 2019 (RTM-CU8-GDR) (KB4583459) - 15.0.4083.2 (X64)
Nov 2 2020 18:35:09
Copyright (C) 2019 Microsoft Corporation
Express Edition (64-bit) on Linux (Ubuntu 18.04.5 LTS) <X64>
以及SQL服务器的JDBC驱动的最新版本
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>9.2.1.jre8</version>
</dependency>
same documentation page 还列出了有效浮点值的范围:
-1.79E+308 to -2.23E-308, 0 and 2.23E-308 to 1.79E+308
因此,Java Double.MIN_VALUE
超出范围。这有效:
try (PreparedStatement s = connection.prepareStatement("select 2.23E-308, ?")) {
s.setDouble(1, 2.23E-308);
try (ResultSet rs = s.executeQuery()) {
while (rs.next()) {
System.out.println(rs.getDouble(1));
System.out.println(rs.getDouble(2));
}
}
}
制作中:
2.23E-308
2.23E-308
虽然它没有解释为什么绑定变量被正确回显。
运行 以下 JDBC 代码与 SQL 服务器:
try (PreparedStatement s = connection.prepareStatement("select 4.9E-324, ?")) {
s.setDouble(1, 4.9E-324);
try (ResultSet rs = s.executeQuery()) {
while (rs.next()) {
System.out.println(rs.getDouble(1));
System.out.println(rs.getDouble(2));
}
}
}
结果是:
0.0
4.9E-324
因此,虽然绑定值被正确回显,但文字却没有。这怎么解释呢? I've noticed in the docs.
Any float value less than 5E-18 (when set using either the scientific notation of 5E-18 or the decimal notation of 0.0000000000000000050000000000000005) rounds down to 0. This is no longer a restriction as of SQL Server 2016 (13.x).
但我使用的是 SQL Server 2019
select @@version
产量:
Microsoft SQL Server 2019 (RTM-CU8-GDR) (KB4583459) - 15.0.4083.2 (X64)
Nov 2 2020 18:35:09
Copyright (C) 2019 Microsoft Corporation
Express Edition (64-bit) on Linux (Ubuntu 18.04.5 LTS) <X64>
以及SQL服务器的JDBC驱动的最新版本
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>9.2.1.jre8</version>
</dependency>
same documentation page 还列出了有效浮点值的范围:
-1.79E+308 to -2.23E-308, 0 and 2.23E-308 to 1.79E+308
因此,Java Double.MIN_VALUE
超出范围。这有效:
try (PreparedStatement s = connection.prepareStatement("select 2.23E-308, ?")) {
s.setDouble(1, 2.23E-308);
try (ResultSet rs = s.executeQuery()) {
while (rs.next()) {
System.out.println(rs.getDouble(1));
System.out.println(rs.getDouble(2));
}
}
}
制作中:
2.23E-308
2.23E-308
虽然它没有解释为什么绑定变量被正确回显。