DBupdate와 DBselect가 DAO만드는 과정에서 반복적으로 등장하여 미리 템플릿을 만들어 사용해주었다.
템플릿 생성 후
DBupdate ctrl+space /DBselect ctrl+space 로 자동완성이 가능하다.

DBselect
		Connection conn=null;
		PreparedStatement pstmt=null;
		ResultSet rs=null;
		try {
			conn=new DbcpBean().getConn();
			String sql="";
			pstmt=conn.prepareStatement(sql);
			// ? 에 값 바인딩 
			
			rs=pstmt.executeQuery();
			while(rs.next()) {
				
			}
		}catch(Exception e) {
			e.printStackTrace();
		}finally {
			try {
				if(rs!=null)rs.close();
				if(pstmt!=null)pstmt.close();
				//connection pool 에 반납하기 
				if(conn!=null)conn.close(); 
			}catch(Exception e) {}
		}	
DBsupdate
		Connection conn=null;
		PreparedStatement pstmt=null;
		int flag=0;
		try {
			conn=new DbcpBean().getConn();
			String sql="";
			pstmt=conn.prepareStatement(sql);
			// ? 에 값 바인딩 하기
			
			flag=pstmt.executeUpdate();
		}catch(Exception e) {
			e.printStackTrace();
		}finally {
			try {
				if(pstmt!=null)pstmt.close();
				if(conn!=null)conn.close();
			}catch(Exception e) {}
		}
		if(flag>0) {
			return true;
		}else {
			return false;
		}'프로그래밍 기초 > JAVA' 카테고리의 다른 글
| [Java]접근지정자 (0) | 2020.02.11 | 
|---|---|
| [JAVA]instaceof 연산자 (0) | 2020.01.30 | 
| [JAVA]자동완성 만드는 Templates (0) | 2020.01.09 | 
 
                  
                