我正在尝试对表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();
}
}
预期的结果看起来像这样
System.out.println(rs.getString("supplierCnt"));
此代码块引用的字符串与]不同。>
SELECT city, COUNT(supplierNum) AS suplierCnt "+
请注意,列名不匹配。
使用