我已经尝试开发计数值显示在我的 apache-tomcat 控制台窗口上。 这里使用以下代码:
public class RetailerWs {
public int data(){
int count=0;
count++;
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/pro","root","");
PreparedStatement statement = con.prepareStatement("select * from orders where status='Q' AND date=CURDATE()");
ResultSet result = statement.executeQuery();
}
catch(Exception exc){
System.out.println(exc.getMessage());
}
return count;
}
}
我的另一个类是:
public class Demo {
public static void main(String[] args){
RetailerWs obj = new RetailerWs();
System.out.println(obj.data());
}
}
在我的数据库中有 2 个值匹配上面的查询。但输出显示始终是 1。为什么这里发生 dis 错误。请帮助我这里使用了什么循环条件。给我一些解决方案。
最佳答案
您实际上并不是在查看查询结果。 count
为 1,因为代码前面的 count++
。
你需要这样的东西:
while(result.next()) {
// Do something with the row returned.
// e.g. count += result.getInt[1]; if the first col is a count.
}
关于java - 计数值显示在 apache-tomcat 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11771583/