//creating a resultset + connecting with the connection method and typing in query
ResultSet rowCount = MainApp.dataBaseSelect("SELECT COUNT(isFoundStatus) FROM damageclaim");
//creating int variable but needs a value since in later row it says ' might not be initalized '
int rowCountInt = 0;
//giving the resultset to the int.
while (rowCount.next()){
rowCountInt = rowCount.getInt("isFoundStatus");
}
//testing with system out
System.out.println(rowCountInt);
我希望获取数据库行的长度,但由于某种原因它不起作用,而数据库的其他连接却可以工作。
我得到的错误:找不到该列,即使我确实拥有它......
最佳答案
让我们假设您正在使用 JDBC。在这种情况下,您需要执行以下两件事之一:
给您的列起别名,以便您可以按名称引用它:
select count(isFoundStatus) as total from damageclaim; // later on rowCountInt = rowCount.getInt("total");
使用列索引来获取第一个值:
select count(isFoundStatus) from damageclaim; // later on rowCountInt = rowCount.getInt(1);
关于java - 为什么我的 SELECT COUNT 查询不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47597469/