Background Image
응용개발
2009.04.15 04:16

jdbc에서 질의 플랜정보 보는 방법

조회 수 16448 추천 수 0 댓글 2
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
JDBC 프로그램에서 질의 플랜정보 보는 방법

CUBRID는  JDBC 프로그램에서 질의 플랜을 출력해주는 메소드를 제공한다.
cubrid.conf 설정

플랜이 출력되려면 CUBRID 설정파일인 $CUBRID/conf/cubrid.conf에 optimization_level=513을 추가하고 DB 서버를 재시작하여야 한다.

# Enable Java Stored Procedure
java_stored_procedure=no
optimization_level=513

간단 예제
다음은 질의 플랜을 화면에 출력하는 간단 예제이다.

import java.sql.*;
import cubrid.jdbc.driver.*; //CUBRIDStatement를 사용하기 위해 import 해야 함.
public class getQueryplan{
        public static void main(String arg[]) throws Exception {
                Connection        conn = null;
                ResultSet         rs = null;
                PreparedStatement  pstmt = null;               
                try {
                        Class.forName("cubrid.jdbc.driver.CUBRIDDriver");
                        conn = DriverManager.getConnection("jdbc:cubrid:localhost:53000:demodb:::","","");
                        conn.setAutoCommit(false); //플랜 정보를 가져오기 위해서는 auto commit을 false로 설정해야 함.
                        String sql = "select host_nation from olympic where host_year = ?";
                        pstmt = conn.prepareStatement(sql);
                        pstmt.setInt(1, 2004);
                        ((CUBRIDStatement)pstmt).setQueryInfo(true);                
                        rs = pstmt.executeQuery();
                        String plan = ((CUBRIDStatement)pstmt).getQueryplan(); // 수행한 질의 플랜 정보를 가져오는 메소드.
                        while(rs.next())
                            System.out.println("host_nation : " + rs.getString(1));
                        conn.commit();
                        System.out.println("plan : " + plan);               
                }catch ( SQLException e ) {
                        e.printStackTrace();
                }catch ( Exception e ) {
                        e.printStackTrace();
                }finally {
                        if (rs != null) rs.close();
                        if (pstmt != null) pstmt.close();
                        if (conn != null) conn.close();
                }
        }
}



  • ?
    hwanyseo 2024.08.28 16:38
    아래 예제와 같이 생생된 Statement이용하여 getQueryplan(String sql)을 사용하면
    서버 설정과 관계 없이 plan정보 확인이 가능합니다. (optimization level 514로 변경 후 실행됨.)
    =============================================================================
    public static void main(String arg[]) throws Exception {
    Class.forName(CLASS_NAME);
    Statement stmt = null;

    try (Connection conn = DriverManager.getConnection(CONNECTION_URL)) {
    String sql = "select host_nation from olympic where host_year = 2004";
    stmt = conn.createStatement();

    String plan = ((CUBRIDStatement) stmt).getQueryplan(sql);
    System.out.println("plan : " + plan);
    if (stmt != null) stmt.close();
    if (conn != null) conn.close();

    } catch (SQLException e) {
    e.printStackTrace();
    }
    }
    ============================================================================
  • ?
    정만영 2024.09.04 09:48

    위 내용들을 참조해 getQueryplan(sql) 함수로 SQL 플랜정보를 출력하는 자바코드입니다, $CUBRID/conf/cubrid.conf 파일에 optimization_level 설정없이 플랜정보를 확인할 수 있습니다.


    import java.sql.*;

    import cubrid.jdbc.driver.CUBRIDStatement;


    public class QueryPlanExample {

        public static void main(String[] args) throws Exception {

            // JDBC 드라이버 로드

            Class.forName("cubrid.jdbc.driver.CUBRIDDriver");


            // 데이터베이스 연결 설정

            String url = "jdbc:cubrid:localhost:33000:demodb:::";

            String username = "public";

            String password = "";


            Connection conn = null;

            Statement stmt = null;

            ResultSet rs = null;


            try {

                // 데이터베이스 연결

                conn = DriverManager.getConnection(url, username, password);

                conn.setAutoCommit(false); // 플랜 정보를 가져오기 위해 auto commit 비활성화


                // SQL 질의

                String sql = "SELECT host_nation FROM olympic WHERE host_year = 2004";


                // Statement 생성 및 질의 실행

                stmt = conn.createStatement();

                rs = stmt.executeQuery(sql);


                // 질의 플랜 정보 가져오기

                String plan = ((CUBRIDStatement) stmt).getQueryplan(sql);

                System.out.println("Query Plan: " + plan);


                // 결과 출력

                while (rs.next()) {

                    System.out.println("============================================");

                    System.out.println("host_nation: " + rs.getString("host_nation"));

                    System.out.println("============================================");

                }


                // 트랜잭션 커밋

                conn.commit();

            } catch (SQLException e) {

                e.printStackTrace();

            } finally {

                // 리소스 정리

                if (rs != null) rs.close();

                if (stmt != null) stmt.close();

                if (conn != null) conn.close();

            }

        }

    }

     



List of Articles
번호 분류 제목 글쓴이 날짜 조회 수
56 응용개발 패키지 형태로 생성된 JAVA class를 JAVA SP에서 사용하기 손승일 2010.02.26 18908
55 응용개발 전체 레코드 개수 확인하는 SP 김승훈 2015.05.07 15338
54 응용개발 응용프로그램에서 질의 처리시 commit/rollback 처리 문제 admin 2008.11.21 22327
53 응용개발 윈도우 환경에서 PHP 모듈 로드를 못 할 경우 해결법 3 Prototype 2009.11.26 25510
52 응용개발 용량이 큰 데이터를 질의로 저장하는 방법 남재우 2009.11.26 12599
51 응용개발 오라클 to CUBRID로 마이그레이션 수행 시 주의사항 cubebridge 2012.11.12 17257
50 응용개발 그루비로 큐브리드 함수(or 프로시저) 만들기 by 행복개발자(cyberuls) 시난 2009.07.14 19241
49 응용개발 weblogic 8.1 에 CUBRID Connection Pool, DataSource 설정 방법 file 웁쓰 2009.07.01 66806
48 응용개발 utf-8로 저장된 한글이 JAVA SP를 사용하여 읽어 오면 깨져 보일때 손승일 2012.03.10 21444
47 응용개발 tomcat 5.5 버전 이상에서 dbcp(커넥션 풀링) 설정법 admin 2008.11.21 29072
46 응용개발 php에서 serialize/unserialize 사용 시 주의할 점 시난 2009.12.29 32263
45 응용개발 maven에서 CUBRID JDBC Driver 추가하기 file 김승훈 2015.12.09 9955
44 응용개발 loadjava 사용 시 inner class 로딩은 어떻게? admin 2008.11.21 27998
» 응용개발 jdbc에서 질의 플랜정보 보는 방법 2 손승일 2009.04.15 16448
42 응용개발 jdbc에서 bit 데이터 타입 사용하기 손승일 2009.04.11 15525
41 응용개발 embedded sql 에서 char 사용시 주의 사항 admin 2008.11.21 19551
40 응용개발 cubrid_fetch_all() php 함수로 만들어 사용하기 file 시난 2009.06.30 19195
39 응용개발 cubrid-php module r2.2 이상 버젼에서 configure시에 주의사항 seongjoon 2010.07.20 14476
38 응용개발 Windows에서 32bit 버전의 PHP 설치 후 CUBRID와 연동 실패 시 해결 방법 file 진우진 2016.03.28 5127
37 응용개발 Windows 환경에서 JAVA SP 사용 utf-8 한글 깨짐 해결 file 손승일 2016.07.01 5116
Board Pagination Prev 1 2 3 Next
/ 3

Contact Cubrid

영업문의 070-4077-2112 / 기술문의 070-4077-2148 / 대표전화 070-4077-2110 / Email. contact_at_cubrid.com
Contact Sales