Notice
Recent Posts
Recent Comments
Link
«   2024/07   »
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 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

WON.dev

GuestbookDao 본문

JSP/GuestBook

GuestbookDao

GAWON 2023. 6. 2. 17:55
package org.joonzis.ex;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.joonzis.mybatis.DBService;

public class GuestbookDao {
	// 필드
	private static SqlSession sqlSession = null;

	// 싱글톤
	private synchronized static SqlSession getsqlSession() {// 기본 생성자(외부에서 접근할 수 없게 private 처리)
		if (sqlSession == null) {
			sqlSession = DBService.getFactory().openSession(false);
		}
		return sqlSession;
	}

	// 메소드
	// 모든 메소드를 static 처리해서 별도 과정 없이 GuestbookDao.메소드명() 으로
	// 메소드를 사용할 수 있다.
	// sqlSession이 필요하면 위에 정의된 getsqlSession()을 호출하면 된다

	// 1.전체 검색
	public static List<GuestbookVO> selectAll(){
		return getsqlSession().selectList("select_all");
	}
	
	// 2. 방명록 추가
	public static int insert(GuestbookVO vo) {
		int result = getsqlSession().insert("insert", vo);
		if(result > 0) {
			getsqlSession().commit();
		}
		return result;
	}
	// 3.상세 페이지 보기
	public static GuestbookVO selectByIdx(int idx) {
		 return  getsqlSession().selectOne("select_One" ,idx);	
	}
	// 4.방명록 삭제
	public static int delete(int vo1) {
		int result = getsqlSession().delete("delete", vo1);
		if(result > 0) {
			getsqlSession().commit();
		}
		return result;
	}
	// 5.방명록 수정
	public static int update(GuestbookVO vo) {
		int result = getsqlSession().update("update", vo);
		if(result > 0) {
		   getsqlSession().commit();
		}
		return result;
	}
	
	
	
	
}

'JSP > GuestBook' 카테고리의 다른 글

download  (0) 2023.06.02
GuestbookVO  (0) 2023.06.02
sqlmap.xml  (0) 2023.06.02
guestbook.xml  (0) 2023.06.02
DBService  (0) 2023.06.02