이 기사에서는 커서를 사용하여 페이징 쿼리를 구현하는 JDBC 방법에 대해 설명합니다. 다음과 같이 참조에 대해 공유하십시오.
/*** 한 번에 데이터베이스에서 최대 MaxCount 레코드를 쿼리하십시오* @Param SQL* @param startNo에서 전달 된 SQL 문은* @param maxcount에서 시작하여 총*/public void getData (String sql, int startNo, int maxcount) {connection connection.getConnection (); {// conn.preparestatement (sql, cursor type, 레코드를 업데이트 할 수 있습니까?); // cursor type : // resultSet.type_forword_only : cursor // resultSet.type_scroll_insensitive : scrollable 만 입력하십시오. 그러나 다른 사용자의 데이터베이스 변경에 영향을받지 않습니다. // resultSet.type_scroll_sensentive : 스크롤 가능. 이 레코드는 다른 사용자가 데이터베이스를 변경하면 변경됩니다. // 레코드를 업데이트 할 수 있습니까? // 레코드의 최대 쿼리는 pstat.setmaxrows (startNo+maxCount-1); resultet rs = pstat.executeQuery (); // 커서를 첫 번째 레코드로 이동 rs.first (); // 커서는 첫 번째 레코드로 이동하여 출력 rs.rsolative (startNo-2); while (rs.next ()) system.out.println (rs.getint (1)); } catch (sqlexception e) {e.printstacktrace (); }}/*** 데이터베이스에서 모든 레코드를 쿼리 한 다음 커서를 사용하여 필요한 MaxCount 레코드* @param startno* @param startno가 통과 한* @param maxcount에서 시작된* @param maxcount 전체*/public void getDatafromall (string sql, int startno, int maxcount)에서 몇 개의 레코드를 찍은 수 try {proadestatem pstat = conn.preparestatement (sql, resultset.type_scroll_insensive, resultset.concur_read_only); resultet rs = pstat.executeQuery (); rs.first (); rs.rsirative (startno-1); int i = startno-1; while (i <startno + maxCount-1 &&! rs.isafterlast ()) {System.out.println (rs.getint (1)); i ++; rs.next (); }} catch (sqlexception e) {e.printstacktrace (); }}Java 관련 컨텐츠에 대한 자세한 내용은이 사이트의 주제를 확인하십시오 : "Java 데이터 구조 및 알고리즘 자습서", "Java 파일 및 디렉토리 운영 기술 요약", "Java Operation Dom Node Skills 요약"및 "Java Cache 운영 기술 요약".
이 기사가 모든 사람의 Java 프로그래밍에 도움이되기를 바랍니다.