이니스트 팀블로그
RSS FEED
Home
Tag
MediaLog
LocationLog
Guestbook
Admin
Write
sidebar open
sidebar close
윤재현
달력
이전
다음
2025.2
일
월
화
수
목
금
토
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
Total
Today
Yesterday
카테고리
분류 전체보기
(57)
HTML/CSS
(4)
JAVASCRIPT
(18)
FLASH
(1)
JSP
(8)
DB
(9)
MSSQL
(0)
ORACLE
(4)
MYSQL
(3)
SERVER
(5)
사는이야기
(0)
공지사항
태그목록
IE6 max-height
selectbox
이미지 리사이즈
jQuery
최근에 올라온 글
최근에 달린 댓글
최근에 받은 트랙백
글 보관함
링크
뽑아먹을만 합니다-1..
함수 작성시 중복 줄이기
2009. 4. 3. 11:31
from
카테고리 없음
// Member Connection객체 얻어오기 public Connection getMemberConnection() { conn = null; try { Context ctx = null; //ctx = getContext(); ctx = new InitialContext(); if(ctx == null ) throw new Exception("Boom - No Context"); DataSource source = (DataSource)ctx.lookup(memberDataSourceName); conn = source.getConnection(); } catch(Exception e) { System.out.println("ERROR: No DataSource is registered under the name"); System.out.println(e); e.printStackTrace(); } return conn; } // 교수진 소개 Connection객체 얻어오기 public Connection getIntroduceConnection() { conn = null; try { Context ctx = null; //ctx = getContext(); ctx = new InitialContext(); if(ctx == null ) throw new Exception("Boom - No Context"); DataSource source = (DataSource)ctx.lookup(introduceDataSourceName); conn = source.getConnection(); } catch(Exception e) { System.out.println("ERROR: No DataSource is registered under the name"); System.out.println(e); e.printStackTrace(); } return conn; }
위위 코드는 DataSource 이름 딱 한줄 틀리다.
이걸 함수로 하나 하나 만들다보면 나중에 자잘한 수정할때마다 전부 고쳐줘야 하는데 이거 엄청귀찮고 가끔 빼먹는다.
// 기본 Connection객체 얻어오기 public Connection getConnection() { return getConnection(memberDataSourceName); } public Connection getConnection( String _dataSourceName ) { conn = null; try { Context ctx = null; //ctx = getContext(); ctx = new InitialContext(); if(ctx == null ) throw new Exception("Boom - No Context"); DataSource source = (DataSource)ctx.lookup(_dataSourceName); conn = source.getConnection(); } catch(Exception e) { System.out.println("ERROR: No DataSource is registered under the name"); System.out.println(e); e.printStackTrace(); } return conn; }
앞으로는 위와같이 썼으면한다.
영재야;;
미안, 너 아니구나~
공유하기
게시글 관리
이니스트 팀블로그
저작자표시
비영리
동일조건
Posted by
윤재현
:
티스토리툴바