▩ Eclipse Plugin - DbEdit - PL/SQL(SQL Script, Stored Procedure...)을 실행 할 수 없습니다.
1. 설치 - http://sourceforge.net/projects/dbedit
- download 받은 후 features, plugins 폴더에 있는 파일을 eclipse의 features, plugins 폴더로 복사 후 eclipse를 재 시작하면 인식이 됩니다.
- 재 시작 한 후 Customize Perspective에서 DbEdit관련 항목을 선택합니다.
2. 오라클 드라이버 설치 - 드라이버 위치: C:\oracle\ora92\jdbc\lib\classes12.jar 파일을 이용합니다.
- classes12.jar 파일을 복사하여 "G:\ejb\eclipse\lib"에 갖다 붙입니다.
※ MySQL 드라이버의 설치 - http://www.mysql.com
- MySQL Connector/J 링크를 클릭하고 zip파일을 다운 받아 압축을 풉니다.
- "mysql-connector-java-3.1.7-bin.jar" 파일을 복사하여 "G:/ejb/eclipse/lib"에 갖다 붙입니다.
3. 오라클 접속 - 접속명 : ora91_system - JDBC Driver: oracle.jdbc.driver.OracleDriver - Server URL : jdbc:oracle:thin:@172.16.6.21:1521:ora91 - User : system - Password : oracle (Save Password Check)
- Add Archive: 오라클 드라이버 경로 지정 "G:/ejb/eclipse/lib/classes12.jar 파일을 지정합니다.
※ MySQL 접속 - JDBC Driver: org.gjt.mm.mysql.Driver - Server URL: jdbc:mysql://127.0.0.1:3306/java?useUnicode=true&characterEncoding=euckr - G:/ejb/eclipse/lib/mysql-connector-java-3.1.12-bin.jar 파일을 추가합니다.
▩ Oracle Setting --------------------------------------------------------------------------- --TS_jsp1000_05_1: TS_수강과목시간_수강월_자신의 IP조합
CREATE TABLESPACE TS_ejb2030_06_1 datafile 'D:\oracledata\200606\TS_ejb2030_06_1.dbs' size 20M default storage (initial 128k next 64k pctincrease 10);
- 테이블 스페이스 목록 보기 . SELECT tablespace_name, status, contents FROM dba_tablespaces ORDER BY tablespace_name;
- 테이블 스페이스의 사용 가능한 공간 보기 . SELECT tablespace_name, bytes, blocks FROM dba_free_space ORDER BY tablespace_name;
2. TableSpace의 삭제 : DROP TABLESPACE 테이블스페이스명; - 테이블 스페이스를 삭제해도 하드디스크상에 데이터 파일은 남아 있음으로 "D:\oracledata\200601" 상에서도 파일을 삭제해야 합니다.
DROP TABLESPACE TS_jsp2030_12_1; SELECT tablespace_name, status, contents FROM dba_tablespaces ORDER BY tablespace_name;
▩ 사용자 계정 생성 및 권한 지정 - 계정의 종류 . SYS: 오라클 데이터베이스 관리자 . SYSTEM: 오라클 데이터베이스 관리자, 모든 권한이 SYS와 같으나 데이터베이스 생성 권한 없음 . SCOTT, HR: SAMPLE 사용자 계정
1. 계정의 생성 -jsp2030_02_1: 수강과목시간_수강월_자신의 IP조합
create user ejb2030_06_1 identified by oracle default tablespace TS_ejb2030_06_1 temporary tablespace temp;
- 등록된 계정 목록 보기 SELECT username, user_id FROM dba_users ORDER BY username;
2. 사용자 삭제 DROP USER 계정명
3. 권한 주기 - connect : 접속, 쿼리 실행, 테이블 생성 - resource : view, stored Procedure 등 서버의 자원을 만들고 쓸수 있는 권한
GRANT connect, resource to ejb2030_06_1;
>>>>> 평일반 20시 30분부 ------------------------------------------------------------------ CREATE TABLESPACE TS_ejb2030_06_1 datafile 'D:\oracledata\200606\TS_ejb2030_06_1.dbs' size 20M default storage (initial 128k next 64k pctincrease 10);
create user ejb2030_06_1 identified by oracle default tablespace TS_ejb2030_06_1 temporary tablespace temp;
GRANT connect, resource to ejb2030_06_1;
>>>>> 세미나2실 전체 설정 ------------------------------------------------------------------ --테이블 스페이스 생성 CREATE TABLESPACE TS_ejb1600_06_201 datafile 'C:\oracle\oradata\200606\TS_ejb1600_06_201.dbs' size 20M default storage (initial 128k next 64k pctincrease 10);
--계정생성 create user ejb1600_06_201 identified by oracle default tablespace TS_ejb1600_06_201 temporary tablespace temp;
--권한지정 GRANT connect, resource to ejb1600_06_201;
▩ ConnectionPool의 생성 및 환경 설정 - Connection 객체를 미리 생성하여 속도향상을 가져온다. - 많은 접속자수로 인해 서버의 리소스가 바닥나지 않도록 관리할 수 있다. - connection 객체를 가지고 있다.
- http://127.0.0.1:7001/console
1. Connection Pool의 등록 - Name : Oracle Connection Pool - Database Name: ora91(SID 이름 지정) - Host Name : 172.16.6.21 - Port : 1521 - Database User Name: ejb2030_06_1 - Password : oracle
2. DataSource 생성 및 환경설정 - JNDI Name: ora91
▩ Weblogic상에서의 Connection Pooling 실습
1. C:/bea/user_projects/domains/ejb/startWebLogic.cmd 파일 38번째 라인 부근 수정 - false, true사이에 공백을 절대 삽입하지 말것, 서블릿이나 JSP를 수정했을 때 자동으로 수정된 파일을 적용받을 수 있게 설정 set PRODUCTION_MODE=false 로 변경하고 개발이 완료되면 set PRODUCTION_MODE=true 로 변경합니다.
2. 폴더 구조 생성 - C:/bea/user_projects/domains/ejb/applications/web . html, jsp 파일이 저장됨 - C:/bea/user_projects/domains/ejb/applications/web/WEB-INF . web.xml, weblogic.xml 환경설정 파일 - C:/bea/user_projects/domains/ejb/applications/web/WEB-INF/classes . Servlet, Beans가 저장됨 - C:/bea/user_projects/domains/ejb/applications/web/WEB-INF/lib . jar파일 같은 라이브러리 파일이 저장됨
- 서버에 등록한 Application이 인식이 안될경우 http://127.0.0.1:7001/console에서 등록하면 정상적으로 실행 할 수 있습니다.
3. Web Application 환경 설정 파일 생성 - weblogic서버가 실행되고 있는 가운데 xml파일을 수정하면 weblogic서버를 재시작하거나 console에서 redeploy를 실행합니다.
>>>>> C:/bea/user_projects/domains/ejb/applications/web/WEB-INF/web.xml <?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>Weblogic 8.1 Connection Pool</display-name> <description> Weblogic 8.1 Connection Pool </description>
<!-- 시작 파일 목록 지정 --> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.jsp</welcome-file> </welcome-file-list>
</web-app>
4. Weblogic Web Application 환경 설정 파일 생성 - <context-root>태그의 값으로 "_"를 붙이면 안됩니다.
>>>>> web/WEB-INF/weblogic.xml <?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE weblogic-web-app PUBLIC "-//BEA Systems, Inc.//DTD Web Application 8.1//EN" "http://www.bea.com/servers/wls810/dtd/weblogic810-web-jar.dtd">
<weblogic-web-app> <charset-params> <input-charset> <resource-path>/*</resource-path> <java-charset-name>KSC5601</java-charset-name> </input-charset> </charset-params>
<!--URL 접근 경로 이름--> <context-root>/jsp</context-root>
</weblogic-web-app>
5. JDBC thin드라이버를 이용한 JDBC 프로그래밍(MS-SQL, Oracle 9i) - 인식이 안되면 weblogic console에서 'Deployments' -- 'Web Application Modules'을 등록해 줍니다. - 웹로직 서버에 등록되는 jsp임으로 웹로직 서버의 위치 정보가 필요 없습니다.
>>>>> domains/ejb/applications/web/tablelist.jsp, http://127.0.0.1:7001/jsp/tablelist.jsp <%@ page contentType="text/html;charset=EUC-KR"%> <%@ page import="java.sql.*"%> <%@ page import="javax.sql.*"%> <%@ page import="javax.naming.*"%> <html> <head> <title> 사용자가 가지고 있는 모든 테이블 보기 </title> </head> <body> <h2>Connection/DataSource/Transaction Test<h2><br><br> <h3> <% Context ctx = null; DataSource ds = null; Connection con = null; Statement stmt = null; ResultSet rs = null;
String sql = "select * from tab";
try{ //JNDI 서비스를 사용하기위해 초기화 작업을 합니다. ctx = new InitialContext(); ds = (javax.sql.DataSource)ctx.lookup("ora91"); con = ds.getConnection();
//트랜잭션을 개발자가 통제합니다. con.setAutoCommit(false); stmt = con.createStatement(); rs = stmt.executeQuery(sql); out.println("테이블 리스트<br>"); out.println("----------------------<br>"); while(rs.next()){ out.println(rs.getString(1) + " " + rs.getString(2)); out.println("<br>"); }
//트랜잭션을 적용 합니다. con.commit(); }catch(Exception e){ //트랜잭션을 취소합니다. con.rollback(); out.println(e.toString()); }finally{ //원래의 값으로 변경합니다. con.setAutoCommit(true); if(rs != null){ try{ rs.close(); }catch(SQLException ex){} } if(stmt != null){ try{ stmt.close(); }catch(SQLException ex){} } if(con != null){ try{ con.close(); }catch(SQLException ex){} } } // finally
%> </h3> </body> </html>
6. JTA를 이용한 분산 트랜잭션의 이용 - 2단계 커밋을 지원하는 분산 트랜잭션 지원
- XA thin드라이버를 이용한 JDBC 프로그래밍(MS-SQL, Oracle 9i)
- 분산 트랜잭션은 JTA Api 사용을 위해 "javax.transaction.*" 패키지를 임포트합니다.
- Transaction 관리 객체를 따로 생성합니다. Connection의 범위를 벗어남으로 Connection에서 트랜잭션을 관리하지 않습니다.
- 실습용 테이블 CREATE TABLE book( num number(5) not null )
>>>>> xa_tablelist.jsp, http://127.0.0.1:7001/jsp/xa_tablelist.jsp <%@ page contentType="text/html;charset=EUC-KR"%> <%@ page import="java.sql.*"%> <%@ page import="javax.sql.*"%> <%@ page import="javax.naming.*"%> <%@ page import="javax.transaction.*"%> <html> <head> <title> 사용자가 가지고 있는 모든 테이블 보기 </title> </head> <body> <h2>Connection/DataSource/분산 Transaction Test<h2><br><br> <h3> <% Context ctx = null; DataSource ds = null; Connection con = null; Statement stmt = null; ResultSet rs = null; UserTransaction tx = null;
DataSource ds2 = null; Connection con2 = null; Statement stmt2 = null; ResultSet rs2 = null; String sql = "select * from tab";
try{ ctx = new InitialContext(); tx = (UserTransaction)ctx.lookup("javax.transaction.UserTransaction");
//트랜잭션 시작 tx.begin();
//1번째 데이터베이스의 테이블 리스트 ds = (javax.sql.DataSource)ctx.lookup("ora91xa"); con = ds.getConnection(); stmt = con.createStatement(); rs = stmt.executeQuery(sql); out.println("테이블 리스트<br>"); out.println("----------------------<br>");
while(rs.next()){ out.println(rs.getString(1) + " " + rs.getString(2)); out.println("<br>"); }
out.println("<br><br>"); //2번째 데이터베이스의 테이블 리스트
ds2 = (javax.sql.DataSource)ctx.lookup("ora91xa2"); con2 = ds2.getConnection(); stmt2 = con2.createStatement(); rs2 = stmt2.executeQuery(sql); out.println("테이블 리스트<br>"); out.println("----------------------<br>");
while(rs2.next()){ out.println(rs2.getString(1) + " " + rs2.getString(2)); out.println("<br>"); }
//트랜잭션 적용 tx.commit(); }catch(Exception e){ //트랜잭션 취소 tx.rollback(); out.println(e.toString()); }finally{ if(rs != null){ try{ rs.close(); }catch(SQLException ex){} } if(stmt != null){ try{ stmt.close(); }catch(SQLException ex){} } if(con != null){ try{ con.close(); }catch(SQLException ex){} }
if(rs2 != null){ try{ rs2.close(); }catch(SQLException ex){} } if(stmt2 != null){ try{ stmt2.close(); }catch(SQLException ex){} } if(con2 != null){ try{ con2.close(); }catch(SQLException ex){} }
} // finally %> </h3> </body> </html>
|