try {
ps = connection.prepareStatement("SELECT * FROM project.order WHERE PO_Date >="+startDate+" AND PO_Date <= "+endDate+"");
System.out.println("value of ps "+ps);
ResultSet rs = ps.executeQuery();
System.out.println("value of rs "+rs);
while (rs.next()) {
System.out.println("value of while loop "+rs.next());
ArrayList<String> arrlist = new ArrayList<String>();
System.out.println(rs.getInt(1));
System.out.println(rs.getDate(2));
System.out.println(rs.getString(4));
System.out.println(rs.getString(5));
System.out.println(rs.getString(6));
System.out.println("******************");
Iterator<String> itr = arrlist.iterator();
while (itr.hasNext()) {
System.out.println(itr.next());
}
rs.close();
}
}catch (Exception e) {
System.out.println(e.getMessage());
}
return id;
What I have tried:
And also tried this too but the problem is it is not comparing the whole date format
after converting to date format it is not executing the query..please help me to solve the problem
public int getdata(String startDate, String endDate) {
PreparedStatement ps;
int id = 0;
try {
/*
* SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
* java.util.Date startDat = formatter.parse(startDate);
* java.util.Date endDat = formatter.parse(endDate);
*/
// ps = connection.prepareStatement("select * from project.order Where PO_Date Between " + startDate + "' AND '" + endDate + "'");
//ps = connection.prepareStatement("select * from project.order where PO_Date between ? AND DATE_ADD( ?, INTERVAL 1 DAY) ");
//ps = connection.prepareStatement("SELECT * FROM project.order WHERE PO_Date between ? AND ?");
ps = connection.prepareStatement("SELECT * FROM project.order WHERE PO_Date >= ? AND PO_Date <= ?");
//ps = connection.prepareStatement("SELECT * FROM project.order WHERE PO_Date(now())>= ? AND PO_Date(now())<=?");
/*
* ps.setDate(1, new java.sql.Date(startDate)); ps.setDate(2, new
* java.sql.Date(endDate.getTime()));
*/
ps.setString(1, startDate);
ps.setString(2, endDate);
ResultSet rs = ps.executeQuery();
// System.out.println("value of rs "+rs);
while (rs.next()) {
ArrayList<string> arrlist = new ArrayList<string>();
System.out.println(rs.getString(2));
System.out.println(rs.getInt(1));
System.out.println(rs.getString(4));
System.out.println(rs.getString(5));
System.out.println(rs.getString(6));
System.out.println("***************");
// System.out.print(rs.getDate("endDate"));
Iterator<string> itr = arrlist.iterator();
while (itr.hasNext()) {
System.out.println(itr.next());
}
}
rs.close();
} catch (Exception e) {
System.out.println(e.getMessage());
}
return id;
}
}