'DB'에 해당되는 글 2건
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 |
JAVA DB - Derby
Posted at 2007/05/12 05:38// Posted in 나만의 작업/DataBase
이번에 Derby에 대해 접해볼 기회가 생겨서 조금씩 알아가고 있는데,
왠지 깜찍(?)하다는 느낌이 듭니다.
이 글을 쓰는 목적은 순전~히 버리의 이기적인 내용정리라고 할까요~
이렇게 쓰면서 제 자신이 정리하고자 하는 목적입니다. 제가 이해가 잘못된곳도 있을지도 몰라요~
Derby는 2005년 말에 Apache DB sub project로 제작되었는데
Embed와 Network Server를 둘다 지원해주는 순수 자바로 제작된 DB입니다.
서버로 띄우거나 어플리케이션에 내장하는 것이 가능하기 때문에 따로 DB를 띄우지 않고도 자바 어플리케이션 작성하는 것이 가능합니다. 이것이 큰 장점~
이 아이는, JVM만 설치되어 있으면 인스톨없이 작동되고 프로그램짤때
jar파일만 추가시켜 주면 됩니다.java 5.0부터는 아예 포함하고 있구요.
더 자세한 설명은,
Apache Derby 소개
Network Server 모드는 흔히쓰는 client/server방식 JDBC와 비슷하니, 간단히 하고
접해보지 못한 Embedded Derby 정리하겠습니다.
Eclipse에서 Plugin을 이용하면 Eclipse내부에서 derby Network Server를 시작할수있다.(Network Server일 경우,)
방법
Embedded Derby란?
When an application accesses a Derby database using the Embedded Derby JDBC driver, the Derby engine does not run in a separate process, and there are no separate database processes to start up and shut down. Instead, the Derby database engine runs inside the same Java Virtual Machine (JVM) as the application.
So, Derby becomes part of the application just like any other jar file that the application uses.
Derby Embedded Architecture
JDBC applications and Derby basics
Developing with Apache Derby -- Hitting the Trifecta:
Learn
Get products and technologies
그외,
derby를 떠올리자면 Cloudscape를 빼놓을수 없으니,Cloudscape FAQ 에 derby에 대한 내용도 많이 있습니다.
Derby Reference Manual - http://db.apache.org/derby/docs/10.2/ref/ref-single.html
Tuning Derby - http://www.onjava.com/pub/a/onjava/2007/01/31/tuning-derby.html
헉, 날이 밝아버렸네요... 이제 자야겠습니다~
왠지 깜찍(?)하다는 느낌이 듭니다.
이 글을 쓰는 목적은 순전~히 버리의 이기적인 내용정리라고 할까요~
이렇게 쓰면서 제 자신이 정리하고자 하는 목적입니다. 제가 이해가 잘못된곳도 있을지도 몰라요~
Derby는 2005년 말에 Apache DB sub project로 제작되었는데
Embed와 Network Server를 둘다 지원해주는 순수 자바로 제작된 DB입니다.
서버로 띄우거나 어플리케이션에 내장하는 것이 가능하기 때문에 따로 DB를 띄우지 않고도 자바 어플리케이션 작성하는 것이 가능합니다. 이것이 큰 장점~
이 아이는, JVM만 설치되어 있으면 인스톨없이 작동되고 프로그램짤때
jar파일만 추가시켜 주면 됩니다.
|
3. Database (Top 10중 3번째에 글이 나와있네요)
For a great out-of-the-box development experience with database applications, the final Mustang development kit – though not the Java Runtime Environment (JRE) – will co-bundle the all-Java JDBC database, Java DB based on Apache Derby. Developers will get the updated JDBC 4.0, a well-used API that focuses on ease of use – although it contains many feature additions like special support for XML as an SQL datatype and better integration of Binary Large OBjects (BLOBs) and Character Large OBjects (CLOBs) into the APIs. Additional features that improve ease of use include removal of some JDBC boilerplate and some of the new annotations that make SQL strings embed better into your JDBC application – like decorating yourgetAllUsers()method with an@Query(sql="select * from user")annotation, and that being all you need.
더 자세한 설명은,
Apache Derby 소개
Network Server 모드는 흔히쓰는 client/server방식 JDBC와 비슷하니, 간단히 하고접해보지 못한 Embedded Derby 정리하겠습니다.
Eclipse에서 Plugin을 이용하면 Eclipse내부에서 derby Network Server를 시작할수있다.(Network Server일 경우,)
방법
- Unzip the two Derby Eclipse plugins (derby_core_plugin_10.1.2.zip and derby_ui_plugin_1.1.0.zip) into your eclipse installation folder (ECLIPSE_ROOT). Detailed instructions are available here: http://db.apache.org/derby/integrate/plugin_howto.html#Installing+the+plug-ins
- In your ECLIPSE_ROOT/plugins folder, you should have a folder named org.apache.derby.core_10.1.2. Copy the file derbyclient.jar from that folder to your TOMCAT_ROOT/common/lib folder. This installs the Derby JDBC driver into Tomcat for use in a DataSource.
참고 Creating Database Web Applications with Eclipse
Embedded Derby란?
When an application accesses a Derby database using the Embedded Derby JDBC driver, the Derby engine does not run in a separate process, and there are no separate database processes to start up and shut down. Instead, the Derby database engine runs inside the same Java Virtual Machine (JVM) as the application.
So, Derby becomes part of the application just like any other jar file that the application uses.
Derby Embedded Architecture
JDBC applications and Derby basics
1) Derby embedded basics
- JDBC driver
Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
- Connection URL
Connection conn=DriverManager.getConnection("jdbc:derby:sampleDB명");
Developing with Apache Derby -- Hitting the Trifecta:
Database development with Apache Derby, Part 2 에서 발취한 내용
Learn- Read Developing with Apache Derby -- Hitting the Trifecta: Introduction to Apache Derby (developerWorks, February 2006), the first article in this series, for a gentle introduction to the Apache Derby database.
- Check out the manuals about how to use the Apache Derby database on the Apache Derby project site.
- Learn how to download and install Apache Derby.
- Learn how to properly verify your download.
- Check out the developerWorks Apache Derby project area for articles, tutorials, and other resources to help you get started with Derby today.
- Read the articles and tutorials about the IBM Cloudscape™ database, which is built using the Apache Derby code base.
- Browse for books on these and other technical topics at the Safari bookstore.
- Browse all the Apache articles and free Apache tutorials available in the developerWorks Open source zone.
Get products and technologies
- Download Apache Derby from the Apache Derby project home page.
- Get downloading details on the latest version of IBM Cloudscape.
그외,
derby를 떠올리자면 Cloudscape를 빼놓을수 없으니,Cloudscape FAQ 에 derby에 대한 내용도 많이 있습니다.
Derby Reference Manual - http://db.apache.org/derby/docs/10.2/ref/ref-single.htmlTuning Derby - http://www.onjava.com/pub/a/onjava/2007/01/31/tuning-derby.html
헉, 날이 밝아버렸네요... 이제 자야겠습니다~
'나만의 작업 > DataBase' 카테고리의 다른 글
| [CouchDB] API Cheatsheet (0) | 2009/07/09 |
|---|---|
| [CouchDB] 초간단 Mac에서 CouchDB 실행하기 (0) | 2009/07/07 |
| [CouchDB] 1. CouchDB가 뭐지? (2) | 2009/07/07 |
| [오라클] 초성검색 (2) | 2009/04/28 |
| 자주 쓰지 않아서 잊어버리는 간단한 Oracle SQL문들 (4) | 2009/04/22 |
| Oracle instant client 설치(Mac OSX, Windows) (0) | 2009/01/07 |
| JAVA DB - Derby (4) | 2007/05/12 |
| [Oracle] Introduction to Oracle 9i : SQL (2) | 2007/02/11 |
| [Oracle] sql Vi 편집기 (1) | 2007/02/06 |
-
-
2007/05/12 12:39 [Edit/Del]아하! 제가 착각하고 있었습니다~..지적 감사합니다^^
What's New in Java SE 6 Beta2(Mustang)에 보니
여기서 JavaDB를 소개하고있군요,,ㅎㅎ
-
-



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