20260916231505
This commit is contained in:
1 parent
de05498552
commit
182ed86966
126 files changed
+5900
-766
No files matched your search
@@ -0,0 +1,51 @@
|
||||
import java.sql.*;
|
||||
|
||||
/** 一次性探针:复现 COUNT_BIG 报错。用完即删。 */
|
||||
public class Probe4 {
|
||||
public static void main(String[] args) throws Exception {
|
||||
String url = "jdbc:sqlserver://118.89.70.199:1433;databaseName=FMS;encrypt=true;trustServerCertificate=true";
|
||||
try (Connection conn = DriverManager.getConnection(url, "sa", "zhang520..")) {
|
||||
|
||||
try (Statement st = conn.createStatement();
|
||||
ResultSet rs = st.executeQuery("SELECT COUNT_BIG(1) FROM [b_con_type]")) {
|
||||
rs.next();
|
||||
System.out.println("Statement 无别名: " + rs.getLong(1));
|
||||
} catch (SQLException e) {
|
||||
System.out.println("Statement 无别名 失败: " + e.getMessage());
|
||||
}
|
||||
|
||||
try (Statement st = conn.createStatement();
|
||||
ResultSet rs = st.executeQuery("SELECT COUNT_BIG(1) AS total FROM [b_con_type]")) {
|
||||
rs.next();
|
||||
System.out.println("Statement 有别名: " + rs.getLong(1) + " / getLong(\"total\")=" + rs.getLong("total"));
|
||||
} catch (SQLException e) {
|
||||
System.out.println("Statement 有别名 失败: " + e.getMessage());
|
||||
}
|
||||
|
||||
try (PreparedStatement ps = conn.prepareStatement("SELECT COUNT_BIG(1) FROM [b_con_type]");
|
||||
ResultSet rs = ps.executeQuery()) {
|
||||
rs.next();
|
||||
System.out.println("PreparedStatement 无别名 getLong(1): " + rs.getLong(1));
|
||||
} catch (SQLException e) {
|
||||
System.out.println("PreparedStatement 无别名 失败: " + e.getMessage());
|
||||
}
|
||||
|
||||
try (PreparedStatement ps = conn.prepareStatement("SELECT COUNT_BIG(1) AS total FROM [b_con_type]");
|
||||
ResultSet rs = ps.executeQuery()) {
|
||||
rs.next();
|
||||
System.out.println("PreparedStatement 有别名 getLong(1): " + rs.getLong(1));
|
||||
} catch (SQLException e) {
|
||||
System.out.println("PreparedStatement 有别名 失败: " + e.getMessage());
|
||||
}
|
||||
|
||||
System.out.println("列类型: " + columnType(conn, "SELECT COUNT_BIG(1) FROM [b_con_type]"));
|
||||
}
|
||||
}
|
||||
|
||||
private static String columnType(Connection conn, String sql) throws SQLException {
|
||||
try (PreparedStatement ps = conn.prepareStatement(sql); ResultSet rs = ps.executeQuery()) {
|
||||
ResultSetMetaData md = rs.getMetaData();
|
||||
return md.getColumnLabel(1) + " / " + md.getColumnTypeName(1) + " / type=" + md.getColumnType(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user