使用JdbcTemp查詢少了一條記錄

freesea1發表於2011-01-07
在JdbcTemp中

public List queryMultiObject(Collection queryParams, String sqlquery, int start, int count) throws Exception {
		Debug.logVerbose("[JdonFramework]--> enter queryMultiObject from:" + start + " size:" + count, module);
		Connection c = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		List items = new ArrayList(count);
		try {
			c = dataSource.getConnection();
			DbUtil.testConnection(c);
			ps = c.prepareStatement(sqlquery, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
			Debug.logVerbose(sqlquery, module);
			jdbcUtil.setQueryParams(queryParams, ps);
			rs = ps.executeQuery();
			if (DbUtil.supportsFetchSize)
				rs.setFetchSize(count);
			if (start >= 0 && rs.absolute(start + 1)) {//這裡是不是有問題
				do {
					items = jdbcUtil.extract(rs);
				} while ((rs.next()) && (--count > 0));
			}
		} catch (SQLException se) {
			throw new Exception("SQLException: " + se.getMessage());
		} catch (Exception ex) {
			Debug.logError(ex, module);
			throw new Exception(ex);
		} finally {
			if (rs != null)
				rs.close();
			if (ps != null)
				ps.close();
			if (c != null)
				c.close();
		}
		return items;
	}
<p class="indent">

資料表中本來有6條記錄,每次查詢都是5條
這個要去除rs.absolute(start + 1)才正確

相關文章