Tuesday, 28 August 2018

Why the query does not return a value

Why this query is not returning any value. There are values in my database with in that range

value input are
Date startDate = (Date) data.get("startDate");//2014-04-01
Date endDate = (Date) data.get("endDate");//2014-04-30
int pagesize=10;

sql query is
String query = "select * from bill_details "
             + " where status=? "
             + " AND date(add_date) BETWEEN  " + startDate + "  AND  " + endDate
             + " order by add_date  desc limit " + pagesize;

ps = con.prepareStatement(query);
ps.setString(1, dataStatus);
System.out.println("Before execution");
res = ps.executeQuery();


Try this:
Date startDate = (Date) data.get("startDate");//2014-04-01
Date endDate = (Date) data.get("endDate");//2014-04-30
int pagesize=10;

String query = "select * from bill_details "
                + " where status=? "
                + " AND date(add_date) BETWEEN  ? AND ?"
                + " order by add_date  desc limit ?";

    ps = con.prepareStatement(query);
    ps.setString(1, dataStatus);
    ps.setDate(2, startDate);
    ps.setDate(3, endDate);
    ps.setInt(4, pagesize);
    System.out.println("Before execution");
    res = ps.executeQuery();

0 comments:

Post a Comment