Table of Contents

Oracle

Port 변경

Windows cannot find 'http:/.127.0.0.1:%HTTPPORT%/apex/f?p=4950'. 
Make sure you typed the name correctly, and then try again.

  sqlplus /nolog
  conn /as sysdba

  #현재포트확인
  SELECT DBMS_XDB.GETHTTPPORT() FROM DUAL

  #9090포트로 변경
  EXEC DBMS_XDB.SETHTTPPORT(9090)

JDBC 예제

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class OcracleTest {

    public static void main(String[] args) {
        String DB_URL = "jdbc:oracle:thin:@127.0.0.1:1521:XE";
        String DB_USER = "hyuk";
        String DB_PASSWORD = "hyuk";

        Connection conn = null;
        Statement stmt = null;
        PreparedStatement ptmt = null;
        
        ResultSet rs = null;

        String query = "SELECT * FROM emp";
        try {
            // 드라이버를 로딩한다.
            Class.forName("oracle.jdbc.driver.OracleDriver");
        } catch (ClassNotFoundException e ) {
            e.printStackTrace();
        }

        try {
            // 데이터베이스의 연결을 설정한다.
            conn = DriverManager.getConnection(DB_URL, DB_USER, DB_PASSWORD);

            // Statement를 가져온다.
            //stmt = conn.createStatement();
            ptmt = conn.prepareStatement(query);
            
            // SQL문을 실행한다.
            //rs = stmt.executeQuery(query);
            rs = ptmt.executeQuery();
            
            while (rs.next()) {
                String empno = rs.getString(1);
                String ename = rs.getString(2);
                String job = rs.getString(3);
                String mgr = rs.getString(4);
                String hiredate = rs.getString(5);
                String sal = rs.getString(6);
                String comm = rs.getString(7);
                String depno = rs.getString(8);
                // 결과를 출력한다.
                System.out.println( 
                    empno + " : " + ename + " : " + job + " : " + mgr
                    + " : " + hiredate + " : " + sal + " : " + comm + " : "
                + depno); 
            }
        } catch ( Exception e ) {
            e.printStackTrace();
        } finally {
            try {
                // ResultSet를 닫는다.
            	if(rs != null)
            		rs.close();
            	
                // Statement를 닫는다.
            	if(stmt != null)
            		stmt.close();
                
            	if(ptmt != null)
            		ptmt.close();
                
                // Connection를 닫는다.
            	if(conn != null)
            		conn.close();
            } catch ( SQLException e ) {}
        }
    }
}