(3), (4)에서는...
absolute를 이용하여 특정 위치를 결과를 뽑아서 사용할 경우의 속도 비교입니다.
5만건의 데이터를 쿼리한 것에서... 1001번째부터 1100까지 100개의 값을
추출하는 소스 입니다.

=============================================
while에서 뽑아오는 소스
--------------------------------------------------------------------------------

import java.sql.*;
import java.util.Vector;

public class DBTest6 {
        
        Vector result = new Vector();
        
        public void init() {
                
                long start_full = System.currentTimeMillis();
                
                String musician, music_subject, music_year, music_write, music_compose = null;
                Connection conn = null;
                Statement stmt = null;
                
                try {
                        Class.forName("org.gjt.mm.mysql.Driver");
                }catch (ClassNotFoundException ex) {
                        System.err.println("ClassNotFoundException: " + ex.getMessage());
                }

                try{
                        conn = DriverManager.getConnection("jdbc:mysql://localhost/music","music","music");

                        if(conn != null)  {
                                stmt = conn.createStatement();
                                
                                long start = System.currentTimeMillis();

                                ResultSet rst = stmt.executeQuery("select musician, music_subject, music_year, music_write, music_compose from musictest");                                
                                
                                long end = System.currentTimeMillis();
                                double res1 = (double)(end - start) / 1000;
                                //System.out.println("start1 : "+start);
                                //System.out.println("end2  : "+end);
                                System.out.println("res1  : "+res1+"초");
                                
                                long start2 = System.currentTimeMillis();
                                                                                                
                                while(rst.next()) {
                                        musician = rst.getString(1);
                                        music_subject = rst.getString(2);
                                        music_year = rst.getString(3);
                                        music_write = rst.getString(4);
                                        music_compose = rst.getString(4);
                                        
                                        Vector row = new Vector();
                                        row.add(musician);
                                        row.add(music_subject);
                                        row.add(music_year);
                                        row.add(music_write);
                                        row.add(music_compose);
                                        result.add(row);
                                }
                                
                                conn.close();
                                long end2 = System.currentTimeMillis();
                                double res2 = (double)(end2 - start2) / 1000;
                                
                                System.out.println("res2  : "+res2+"초");
                        }
                }catch(Exception e) {
                          e.printStackTrace();
                }finally {
                        if ( stmt != null ) try{stmt.close();}catch(Exception e){}
                        if ( conn != null ) try{conn.close();}catch(Exception e){}
                  }
                
                long end_full = System.currentTimeMillis();
                double res_full = (double)(end_full - start_full) / 1000;
                System.out.println("res_full  : "+res_full+"초");
        }
        
        public Vector getResult(){                
                return result;        
        }                
        
        public static void main(String[] args) {
                
                DBTest6 db = new DBTest6();
                db.init();
                Vector result = db.getResult();
                
                long start = System.currentTimeMillis();
                for(int i=1000; i < 1100; i++){
                        Vector row = (Vector)result.get(i);
                        
                        String musician = (String)row.get(0);
                        String music_subject = (String)row.get(1);
                        String music_year = (String)row.get(2);
                        String music_write = (String)row.get(3);
                        String music_compose = (String)row.get(4);
                        
                        System.out.println(musician +" : "+ music_subject + " : "+ music_year + " : "+ music_write + " : "+music_compose);                                                
                }
                long end = System.currentTimeMillis();
                double res2 = (double)(end - start) / 1000;
                System.out.println("res3  : "+res2+"초");
        }
}

---------------------------------------------------------------------------
absolute를 써서 뽑아오는 경우
---------------------------------------------------------------------------

import java.sql.*;
import java.util.Vector;

public class DBTest5 {
        
        Vector result = new Vector();
        
        public void init() {
                
                long start_full = System.currentTimeMillis();
                
                String musician, music_subject, music_year, music_write, music_compose = null;
                Connection conn = null;
                Statement stmt = null;
                
                try {
                        Class.forName("org.gjt.mm.mysql.Driver");
                }catch (ClassNotFoundException ex) {
                        System.err.println("ClassNotFoundException: " + ex.getMessage());
                }

                try{
                        conn = DriverManager.getConnection("jdbc:mysql://localhost/music","music","music");

                        if(conn != null)  {
                                stmt = conn.createStatement();
                                
                                long start = System.currentTimeMillis();

                                ResultSet rst = stmt.executeQuery("select musician, music_subject, music_year, music_write, music_compose from musictest");                                
                                
                                long end = System.currentTimeMillis();
                                double res1 = (double)(end - start) / 1000;
                                System.out.println("res1  : "+res1+"초");
                                
                                long start2 = System.currentTimeMillis();
                                                                                                                
                                int j = 1001;
                                rst.absolute(j);
                                for(int i = 0 ; i < 100 ; i++){
                                        musician = rst.getString(1);
                                        music_subject = rst.getString(2);
                                        music_year = rst.getString(3);
                                        music_write = rst.getString(4);
                                        music_compose = rst.getString(4);
                                        
                                        Vector row = new Vector();
                                        row.add(musician);
                                        row.add(music_subject);
                                        row.add(music_year);
                                        row.add(music_write);
                                        row.add(music_compose);
                                        result.add(row);
                                        
                                        rst.next();
                                }                                
                                
                                conn.close();
                                long end2 = System.currentTimeMillis();
                                double res2 = (double)(end2 - start2) / 1000;
                                
                                System.out.println("res2  : "+res2+"초");                                
                        }
                }catch(Exception e) {
                          e.printStackTrace();
                }finally {
                        if ( stmt != null ) try{stmt.close();}catch(Exception e){}
                        if ( conn != null ) try{conn.close();}catch(Exception e){}
                }

                
                long end_full = System.currentTimeMillis();
                double res_full = (double)(end_full - start_full) / 1000;
                System.out.println("res_full  : "+res_full+"초");
        }
        
        public Vector getResult(){                
                return result;        
        }                
        
        public static void main(String[] args) {
                
                DBTest5 db = new DBTest5();
                db.init();
                Vector result = db.getResult();
                
                long start = System.currentTimeMillis();
                for(int i=0; i < result.size(); i++){
                        Vector row = (Vector)result.get(i);
                        
                        String musician = (String)row.get(0);
                        String music_subject = (String)row.get(1);
                        String music_year = (String)row.get(2);
                        String music_write = (String)row.get(3);
                        String music_compose = (String)row.get(4);
                        
                        System.out.println(musician +" : "+ music_subject + " : "+ music_year + " : "+ music_write + " : "+music_compose);                                                
                }
                long end = System.currentTimeMillis();
                double res2 = (double)(end - start) / 1000;
                System.out.println("res3  : "+res2+"초");
        }
}
=============================================
결과는 (4)에서.. 계속..




***** 아름다운프로님에 의해서 게시물 복사 + 카테고리변경되었습니다 (2003-12-18 17:44)
Posted by 아름프로
BLOG main image

카테고리

분류 전체보기 (539)
이야기방 (19)
토론/정보/사설 (16)
IBM Rational (9)
U-IT (0)
SOA/WS/ebXML (110)
개발방법론/모델링 (122)
J2SE (34)
J2EE (60)
DataBase (39)
Open Projects (30)
BP/표준화 (50)
Apache Projects (15)
Web/보안/OS (22)
Tools (7)
AJAX/WEB2.0 (1)
Linux/Unix (1)
영어 (0)
비공개방 (0)

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

달력

«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28

글 보관함

Total :
Today : Yesterday :