gpt4 book ai didi

java - 从数据库中检索总和

转载 作者:行者123 更新时间:2023-11-30 01:42:26 27 4
gpt4 key购买 nike

       try{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String url = "jdbc:sqlserver://localhost;databaseName=QLLTCK;integratedSecurity=true;";
Connection connection = DriverManager.getConnection(url);
String sql = "SELECT SUM(soSV) AS sumSoSV FROM PHANCONG WHERE tenMH = 'Công nghệ phần mềm chuyên sâu'";
PreparedStatement pst = connection.prepareStatement(sql);
ResultSet rs = pst.executeQuery();
if(rs.next()){
int SumSoSV = rs.getInt("sumSoSV");
JOptionPane.showMessageDialog(null,"Số sinh viên dự thi: " + SumSoSV);
}
}
catch(Exception sqlex){
JOptionPane.showMessageDialog(null, sqlex);
}

我无法从我的 PHANSONG 表中检索 soSV 的总和。它的结果是 0。当我尝试使用 String 而不是 int 时,它的结果是 null。有人能帮我吗?谢谢。

Image

最佳答案

我猜你需要在字符串文字之前添加 N 来处理 unicode 字符:

String sql = "SELECT SUM(soSV) AS sumSoSV FROM PHANCONG WHERE tenMH = N'Công nghệ phần mềm chuyên sâu'"

关于java - 从数据库中检索总和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59488844/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com