我正在使用jdbc sybase驅動程序(jconn3
)執行select語句。我檢查了在isql上手動執行的語句,並且所有行都正確返回。這是對JDBC執行語句:沒有從db返回的行 - 但有要返回的記錄
select * from mytable where date between ? and ?
我添加了日期格式爲yyyy-MM-dd HH:mm:ss
和設置時間值00:00:00開始爲結束日期,日期和23:59:59。
它不工作。行數必須是1000,但有時是770,有時是990,有時是564等。沒有任何特定的行數每次都返回。
之後,我添加了一個額外的執行,只返回行數。首先,我正在執行select count(*) from ...
語句,然後執行select * from ....
,現在`select * from ... query每次都會返回正確數量的記錄。這與緩存無關。奇怪的是,我爲這兩個執行使用了相同的preparedstatement和resultset對象。
關於這個問題的任何想法?
@Rulmeq,這裏是代碼(上加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()){
........
}
向我們顯示您的代碼。 – Goibniu 2012-03-28 14:13:11
@Rulmeq,我添加了有問題的代碼。 – Aykut 2012-03-29 12:42:14
您可以在代碼中包含beginDate和endDate的實例化(定義)。他們似乎是這裏的關鍵。 – 2012-03-29 12:53:26