develog

[Java] 익명 PL/SQL 블럭 실행 본문

Dev/Java

[Java] 익명 PL/SQL 블럭 실행

냐옴 2014. 8. 29. 19:07

public void callAnoymousPlsql(Connection conn) throws Exception {

    CallableStatement cstmt = null;

    String ln = "\n";

    // \r\n ==> ERR

    // \n ==> OK

    // System.getProperty("line.separator") ==> \r\n

    

    try {

        StringBuffer sb = new StringBuffer();

        sb.append("DECLARE" + ln);

        sb.append("BEGIN" + ln);

        sb.append("INSERT INTO AATEST (SEQ, TITLE) VALUES (999, 999);" + ln);

        sb.append("COMMIT;" + ln);

        sb.append("END;" + ln);

        

        String sql = sb.toString();

        System.out.println(sql);

        

        cstmt = conn.prepareCall(sql);

        cstmt.execute();

    } finally {

        if (cstmt != null) {

            cstmt.close();

        }

    }

}

'Dev > Java' 카테고리의 다른 글

memory  (0) 2014.09.10
eclipse.ini  (0) 2014.09.10
[Spring] dbcp 설정  (0) 2014.08.08
[Java] byte <-> int  (0) 2014.07.27
[Java] bit & shift 연산  (0) 2014.07.26
Comments