본문 바로가기

Languages/DataBase

DB2 - DB2 application development: Tracing with the DB2 Universal JDBC Driver




DB2 application development: Tracing with the DB2 Universal JDBC Driver


{
  
  • DB2 에서의 JDBC 사용예제를 연습할 수 있는 페이지 입니다.
  • 물론, IBM 에서 제공하는 사이트이며, 영문입니다. (그래도 대충 알아먹을 수 있어요)

Summary: Trace data at the interface between application and database provides the developer with information to identify program errors and to optimize database access. The DB2?? Legacy JDBC™ Driver is based on the DB2 Call Level Interface (CLI) layer and allows for JDBC or CLI tracing ...... 중략

[샘플코드 - Driver Type 2 에서의 JDBC 연결]




public class LegacyTraceExample

{

    public static void main(String[] args) {

        try {

            // load driver

            Class.forName("COM.ibm.db2.jdbc.app.DB2Driver").newInstance();

 

            // set connection properties

            String databaseUrl = "jdbc:db2:sample";

 

            // get connection

            java.sql.Connection con =

                java.sql.DriverManager.getConnection(databaseUrl, "user", "password");

 

            // execute a query

            java.sql.Statement stmt = con.createStatement();

 

            String query = "SELECT COUNT(*) FROM SYSCAT.TABLES";

            java.sql.ResultSet rs = stmt.executeQuery(query);

 

            while (rs.next()) {

                System.out.println("\n" + query + " = " + rs.getInt(1));

            }

 

            rs.close();

            stmt.close();

            con.close();

        } catch (Exception e) {

            e.printStackTrace();

        }

    }

}

}


자세한 내용은 아래의 주소를 참고하세요.

http://www.ibm.com/developerworks/data/library/techarticle/dm-0506fechner/