Ajax

김덕근·2023년 3월 23일
0

Ajax

목록 보기
1/2

서버 추가 생성

[Servers -> New -> Server선택 ->
server name : Tomcat v9.0 Server at localhost 서버네임 변경 후 -> [생성] 생성 완료 후 -> Serve modules without publishing 체크 후 저장 ]

[jspwork 경로 추가 (webapp 안에 jspwork폴더 생성(servlet→jsp) )]

Package Explorer -> Servers 생성한 이름의 폴더 안에 -> context.xml열기

<Context workDir="C:\workspace\05_Server\community\src\main\webapp\WEB-INF\jspwork">

DataBase Connection Pool(DBCP)

  • 미리 DB와 연결되어 있는 Connection을 일정 개수 만들어 두고
    클라이언트 요청 시 만들어둔 Connection을 빌려주고
    요청 처리 완료 시 다시 반환 받는 기법

    	- 장점 :
    	1) 미리 Connection을 만들어 두기 때문에 요청 시 속도가 빠름
    
    	2) Connection 개수에 제한을 두어 DB에 과도한 요청되는 경우를 방지

context.xml 내부 작성

<Resource
name="jdbc/oracle"
auth="Container"
type="javax.sql.DataSource"
driverClassName="oracle.jdbc.OracleDriver"
url="jdbc:oracle:thin:@localhost:1521:xe"
username="community"
password="1234"
maxTotal="50"
maxIdle="10"
maxWaitMillis="-1"
/>

name : JNDI 이름 Context의 lookup()을 사용하여 자원을 찾을때 사용한다. java:comp/env 디렉터리에서 찾을 수 있다.
auth : 자원 관리 주체 지정(Application 또는 Container)
type : Resource의 타입 지정
driverClassName : JDBC 드라이버 클래스 이름.
maxTotal : DataSource 에서 유지할 수 있는 최대 커넥션 수
maxIdle : 사용되지 않고 풀에 저장될 수 있는 최대 커넥션의 개수. 음수일 경우 제한이 없음
maxWaitMillis : 커넥션 반납을 기다리는 시간(-1은 반환될 때 까지 기다림)
-->


JNDI(Java Naming and Directory Interface API)

  • 디렉토리에 접근하는데 사용하는 JAVA API
  • 애플리케이션(프로그램, 웹앱)은 JNDI를 이용해서 파일 또는 서버 Resource를 찾을 수 있음

<JDBCTemplate getConnection() 메서드 안에 작성>

		Context initContext = new InitialContext();

		// context.xml 파일 찾기
		Context envContext = (Context)initContext.lookup("java:comp/env");

		// DBCP 세팅 <Resource> 태그를 찾아 DataSource 형식의 객체로 얻어오기
		// DataSource : Connection Pool을 구현하는 객체(만들어둔 Connection 얻어오기 가능)
		DataSource ds = (DataSource)envContext.lookup("jdbc/oracle");

		conn = ds.getConnection();

		conn.setAutoCommit(false);
profile
안녕하세요!

0개의 댓글