I am executing the select statement with using jdbc sybase driver (jconn3). I checked the statement with executed manually on isql and all rows returned correctly. The statement which is executing on jdbc :
select * from mytable where date between ? and ?
I added the dateformat as yyyy-MM-dd HH:mm:ss and set the time value as 00:00:00 for begin date and 23:59:59 for end date.
It is not working. The row count must be 1000 but it is sometimes 770, sometimes 990, sometimes 564 etc.. There is no any specific row count which everytime returned.
After that I added an extra execution which returns only row count. First I am executing the select count(*) from ... statement then executing select * from .... and now `select * from … query returns the correct number of records everytime. This can not be related with caching. And weird thing is , I am using same preparedstatement and resultset objects for those two execution.
Any idea on that issue?
@Rulmeq, here is the code (added on 2012-03-29)
ResultSet rs = null;
PreparedStatement ps = null;
ps = myConn.getConnection().prepareStatement("select count(*) from myTable where date between ? and ?");
ps.setDate(1, new java.sql.Date(beginDate.getTime())); // format : yyyy-MM-dd
ps.setDate(2, new java.sql.Date(endDate.getTime())); // format : yyyy-MM-dd
rs = ps.executeQuery();
rs.next();
// some logs here
ps = myConn.getConnection().prepareStatement("select * from myTable where date between ? and ?");
ps.setTimestamp(1, new java.sql.Timestamp(beginDate.getTime())); // format : yyyy-MM-dd hh:mm:ss
ps.setTimestamp(2, new java.sql.Timestamp(endDate.getTime())); // format : yyyy-MM-dd hh:mm:ss
rs = ps.executeQuery();
while(rs.next()){
........
}
Thanks for all but issue has been solved and it was not related with jdbc. It was related with using System.currentTimeMillis() and host system is too fast. That’s why system sometime uses the same ms. I changed the references.