0

これは、データベースから取得している現在の日付情報を取得するためのコードです。正常に動作しています。

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();

      while(result.next()) {
        // Do something with the row returned.
        count++; //if the first col is a count.
      }     
    }
    catch (Exception exc) {
      System.out.println(exc.getMessage());
    }


    return count;
  }
}

私の疑問は、データベースから今月の詳細を取得する方法です。..それを行う方法...私を助けてください。

disは私のデータベースです:

ここに画像の説明を入力してください

ここで出力が必要なのは、上記のアプリケーションを実行した場合、カウント値が表示されることを意味します。出力が必要な場合は、現在の月の詳細です。たとえば、現在の日付情報を取得することは、クエリをチェックしてカウントを表示することを意味します。値は2です。正常に動作しています。ここでクエリを記述しました。

select * from orders where status='Q' AND date=CURDATE()".

正常に動作しています。同じように、今月のstatus = Qのクエリを記述します...出力を2に表示したいのですが、disを実行できません。助けてください。コードを変更するにはどうすればよいですか。

4

2 に答える 2

1

これを試して:

select month(CURDATE())

また

select date_format(now(),'%M')as Month_name

月番号を取得するには

select date_format('2012-07-26','%m')as Month_number

更新された質問への回答:

select count(*) from orders where status='Q' AND date=CURDATE()"

クエリにcount(*)を追加するだけで、結果「2」が得られます

于 2012-08-02T08:54:36.553 に答える
1

ここMONTH()でmysqlの 機能を試してください

于 2012-08-02T08:55:51.047 に答える