java - 计数值显示在 apache-tomcat 上

标签 java mysql apache tomcat soap

我已经尝试开发计数值显示在我的 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/

相关文章:

java - spring-oxm:我可以解码文件的子元素吗?

java - BufferedReader 中跳过和重置方法的一些实际用例是什么?

Java代码和JIT编译

java - 在 (J)Ruby 代码中安装 gems

MySQL 客户端连接

PHP 直接打印到打印机(本地/网络)(卡在后台打印程序中)

php - XDebug 未加载到 PHP(Vista、Apache 模块)中

php - 我该如何优化这个功能?我需要循环用户,然后循环用户提交的数据,并更新值,这需要 > 1 分钟

php - 如何让用户在将文本保存到 MySQL 表之前对其进行操作(使其粗体/斜体)?

java - 无法创建动态 Web 项目?