【问题标题】:count the value is display on apache-tomcat计数值显示在 apache-tomcat 上
【发布时间】:2012-08-02 05:34:22
【问题描述】:

我已经尝试开发计数值显示在我的 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错误。请帮助我这里使用什么循环条件。给我一些解决方案。

【问题讨论】:

    标签: java mysql apache tomcat soap


    【解决方案1】:

    您实际上并没有查看查询的结果。 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.
    }
    

    【讨论】:

    • 我得到了输出。因为我的日期字段以 DATE(yyyy-mm-dd) 格式保存。但是现在我的数据库有日期归档。它以时间戳(int)格式保存。现在如何正在开发这个。请帮助我
    • 你应该为此开始另一个问题,但 Date.getTime() 是你需要开始寻找的地方。
    【解决方案2】:

    在执行查询后添加此行。

    count = 0;
    while ( result.next() ) 
    count++;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-08-01
      • 2018-06-26
      • 1970-01-01
      • 1970-01-01
      • 2018-06-25
      • 2018-09-20
      • 1970-01-01
      相关资源
      最近更新 更多