正在计算行数,但是没有打印到控制台吗?

问题描述 投票:0回答:1

我正在尝试对表supllierNum中的行进行计数,以找出每个供应商拥有的供应量

创建的表代码为:

CREATE TABLE supplier (
  supplierNum CHAR(2)   NOT NULL,
  name CHAR(10) NOT NULL,
  status TINYINT(4) NOT NULL,
  city VARCHAR(10)  NOT NULL,
   PRIMARY KEY (supplierNum)
);

我用于执行查询的语法是

String queary = "SELECT city, COUNT(supplierNum) AS suplierCnt "+
                "FROM supplier "+
                "GROUP BY city "+
                "ORDER BY city DESC";

它使用MySQL工作台工作,当我在eclipse中执行它时,它只显示一个空白终端而没有错误消息,这使我认为它是代码中缺少的东西?

我在try块中使用的完整代码是

    try{
        Connection conn = DriverManager.getConnection(DB_URL, USERNAME, PASSWORD);
        System.out.println("Connected");
        Statement st = conn.createStatement();

        String queary = "SELECT city, COUNT(supplierNum) AS suplierCnt "+
                        "FROM supplier "+
                        "GROUP BY city "+
                        "ORDER BY city DESC";


        ResultSet rs = st.executeQuery(queary); 

        while(rs.next()) {
            System.out.println(rs.getString("supplierCnt"));
            System.out.println(rs.getString("city"));
            space();
            }

    }

预期的结果看起来像这样

enter image description here

java jdbc relational-database
1个回答
0
投票
 System.out.println(rs.getString("supplierCnt"));

此代码块引用的字符串与]不同。>

SELECT city, COUNT(supplierNum) AS suplierCnt "+

请注意,列名不匹配。


0
投票

使用

© www.soinside.com 2019 - 2024. All rights reserved.