Derby에서 paging구현..
Posted at 2007/09/03 23:27// Posted in 나만의 작업
JavaDB인 Derby에서 원하는 행부터 원하는 행까지 출력하고 싶어
막연하게 Oracle에서 rownum을 쓰듯 where절에 rownum > 1 ....
이렇게 썼더니, 당연히 rownum이란게 없다고 나오더라구요..
설마, Oracle에서 rownum, Mysql에서 LIMIT가 derby에 없을까?
쭉~~찾아보니 역시나 없다는 문서를 발견.ㅠㅠ
ONJava.com의 Tuning Derby의 내용중...
막연하게 Oracle에서 rownum을 쓰듯 where절에 rownum > 1 ....
이렇게 썼더니, 당연히 rownum이란게 없다고 나오더라구요..
설마, Oracle에서 rownum, Mysql에서 LIMIT가 derby에 없을까?
쭉~~찾아보니 역시나 없다는 문서를 발견.ㅠㅠ
ONJava.com의 Tuning Derby의 내용중...
Many database servers support specialized SQL constructs that can be used to retrieve a specified subset of query results. For example, in MySQL you'll find the LIMIT and OFFSET keywords, which can be used in SELECT queries. So if you execute a query like this:
select * from tbl LIMIT 50 OFFSET 100
your result set will contain 50 rows starting
from the 100th result, even if the original query returned 100,000
rows. Many other database vendors provide similar functionality through
different constructs. Unfortunately, Derby does not provide such functionality,
so you have to stay with the originalselect * from tblquery and implement a paging mechanism on the application level.
Let's look at the following example:Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance();
Connection connection = DriverManager.getConnection(
"jdbc:derby://localhost:1527/testDb;");
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM tbl");
ArrayList allResults = new ArrayList();
int i = 0;
while (rs.next()) {
if (i > 50 && i <= 100) {
// O-R mapping code populate your row from result set
DomainObject domainObject = populate(rs);
allResults.add(modelObject);
}
i++;
}System.out.println("Results Size: " + allResults.size());
불행하게도, derby는 그런 메소드를 제공하지 않아서, full scan을 한후 그 결과값(ResultSet)으로
어플리케이션 레벨에서 페이징 메카니즘을 구현해야한다고 하네요.
구현은 그리 어렵지 않지만, rownum과 같이 편리한 메소드를 왜 아직 제공안하는지.ㅠㅠ
뒤에 더 문서를 보면 OutofMemoryError에 대해 안전하다고 하지만
그래도 찜찜하면 트릭을 써서 명시적으로 얼마까지 로우를 가져올지다른 문서 JavaDB FAQ 내용중에 얼핏보았는데 아직 rownum과 같은 메소드를 현재 제공하지는 않지만
stmt.setMaxRows(101);
이 함수를 써서 이용하라고 합니다..
언젠가는 제공하기를 고려하고 있다고 합니다..
'나만의 작업' 카테고리의 다른 글
| Google Developer Night에 다녀와서,, (14) | 2007/10/17 |
|---|---|
| 다음(Daum) 검색창에서 "@버리"를 쳐보세요 (16) | 2007/10/11 |
| 2007 JCO 오픈소스 컨퍼런스 (10) | 2007/10/02 |
| 일상을 적는 서비스 "oladay" (10) | 2007/09/21 |
| Derby에서 paging구현.. (7) | 2007/09/03 |
| 한국 스프링 사용자 모임(KSUG) 제 4 회 세미나 사전접수가 시작되었네요. (6) | 2007/08/31 |
| 무서운 Web.. ? 검색엔진... (11) | 2007/08/26 |
| firefox가 느릴때.. (10) | 2007/08/04 |
| Safari 3.0 for Windows를 맛본 후 (6) | 2007/07/04 |



setMinRows() 가 있는지는 Derby를 안써봐서 모르겠지만...
일단 없다면 100000개의 데이터 압박이 있군요.
어찌됐던 풀스캔의 압박은...-_-;;
풀스캔의 압박,,ㅠㅠ
그럼 그냥 where 절을 잘 적어서 limit 효과를 볼 수 있지 않을까용? ㅋ
걍 그냥 생각입니다. ㅋㅋ
row가 정말 많을때 rownum이 없을때의 효과를 톡톡히
치르겠죠...