개발환경

생 jdbc 수집 예제...

toogari 2014. 1. 15. 15:47

import java.sql.*;

 

/**

 * Created by sokhoon on 14. 1. 15.

 */

public class KeepAliveSelector {

    public static void main(String[] args) {

        Connection conn = null;

        ResultSet rs = null;

        Statement statement = null;

        try {

            Class.forName("oracle.jdbc.driver.OracleDriver");

            conn = DriverManager.getConnection("jdbc:oracle:thin:@0.0.0.0:1521:DBNAME", "scott", "tiger");

 

            statement = conn.createStatement();

            rs = statement.executeQuery("select 1 from dual");

            while (rs.next()) {

                System.out.println(rs.getString("1"));

            }

 

        } catch (Exception e) {

            e.printStackTrace();

        } finally {

            try {

                if (statement != null) {

                    statement.close();

                }

            } catch (SQLException e) {

            }

            try {

                if (rs != null) {

                    rs.close();

                }

            } catch (SQLException e) {

            }

            try {

                if (conn != null) {

                    conn.close();

                }

            } catch (SQLException e) {

            }

        }

    }

}