dao.MemberDAO.java > MODEL2

본문 바로가기
사이트 내 전체검색

MODEL2

dao.MemberDAO.java

페이지 정보

profile_image
작성자 관리자
댓글 0건 조회 177회 작성일 24-04-12 10:29

본문

package dao;


import java.sql.PreparedStatement;

import java.sql.ResultSet;

import java.sql.Statement;


import model.Member;


public class MemberDAO {


//사용할 객체를 미리 선언

Statement stmt;

PreparedStatement pstmt;

ResultSet rs;

DAO d = new DAO(); //d.getCon() , d.conn 사용 목적

//아이디 존재 여부

public int loginSelect(String id) {

d.getCon();

int num = 0;

try {

String sql = "select count(*) from member where id=?";

pstmt = d.conn.prepareStatement(sql);

pstmt.setString(1, id);

rs = pstmt.executeQuery();

if(rs.next()) {

num = rs.getInt(1);

}

}catch(Exception e) {

e.printStackTrace();

}finally {

try {

rs.close();

pstmt.close();

d.conn.close();

}catch(Exception e) {

e.printStackTrace();

}

}

return num;

}

//회원가입

public void insertMember(Member member) {

d.getCon(); //데이터베이스 연결

try {

String sql = "insert into member values (?,?,?,?,?,?,?,?,?)";

pstmt = d.conn.prepareStatement(sql);

pstmt.setString(1, member.getId());

pstmt.setString(2, member.getPass());

pstmt.setString(3, member.getName());

pstmt.setInt(4, member.getAge());

pstmt.setString(5, member.getGender());

pstmt.setString(6, member.getEmail());

pstmt.setString(7, "1");

pstmt.setString(8, member.getMemo());

pstmt.setString(9, "로컬");

pstmt.executeUpdate();

}catch(Exception e) {

e.printStackTrace();

}finally {

try {

pstmt.close(); //사용 객체 닫음

d.conn.close(); //사용 객체 닫음

}catch(Exception e) {

e.printStackTrace();

}

}

}

//로그인

public Member loginMemberSelect(String id, String pass) {

d.getCon();

Member m = new Member();

try {

String sql = "select * from member where id=? and pass=?";

pstmt = d.conn.prepareStatement(sql);

pstmt.setString(1, id);

pstmt.setString(2, pass);

rs = pstmt.executeQuery();

if(rs.next()) {

m.setId(rs.getString("id")); //id : 데이터베이스 테이블 칼럼명

m.setName(rs.getString("name"));

m.setLevel(rs.getString("level"));

}

}catch(Exception e) {

e.printStackTrace();

}finally {

try {

rs.close();

pstmt.close();

d.conn.close();

}catch(Exception e) {

e.printStackTrace();

}

}

return m;

}

//회원 한명의 정보

public Member oneMember(String id) {

d.getCon();

Member m = new Member();

try {

String sql = "select * from member where id=?";

pstmt = d.conn.prepareStatement(sql);

pstmt.setString(1, id);

rs = pstmt.executeQuery();

if(rs.next()) {

m.setId(rs.getString("id")); //id : 데이터베이스 테이블 칼럼명

m.setPass(rs.getString("pass"));

m.setName(rs.getString("name"));

m.setAge(rs.getInt("age"));

m.setGender(rs.getString("gender"));

m.setEmail(rs.getString("email"));

m.setLevel(rs.getString("level"));

m.setMemo(rs.getString("memo"));

}

}catch(Exception e) {

e.printStackTrace();

}finally {

try {

rs.close();

pstmt.close();

d.conn.close();

}catch(Exception e) {

e.printStackTrace();

}

}

return m;

}

//회원 수정

public void updateMember(Member m) {

d.getCon();

try {

String sql = "update member set pass=?,name=?,age=?,gender=?,email=?,memo=? where id=?";

pstmt = d.conn.prepareStatement(sql);

pstmt.setString(1, m.getPass());

pstmt.setString(2, m.getName());

pstmt.setInt(3, m.getAge());

pstmt.setString(4, m.getGender());

pstmt.setString(5, m.getEmail());

pstmt.setString(6, m.getMemo());

pstmt.setString(7, m.getId());

pstmt.executeUpdate();

}catch(Exception e) {

e.printStackTrace();

}finally {

try {

pstmt.close();

d.conn.close();

}catch(Exception e) {

e.printStackTrace();

}

}

}


//회원가입 - 카카오

public void insertMemberApi(String id) {

d.getCon(); //데이터베이스 연결


try {

String sql = "insert into member (id,name,email,connecttype ) values (?,?,?,?)";

pstmt = d.conn.prepareStatement(sql);


pstmt.setString(1, id);

pstmt.setString(2, "카카오로그인");

pstmt.setString(3, id);

pstmt.setString(4, "카카오");


pstmt.executeUpdate();

}catch(Exception e) {

e.printStackTrace();

}finally {

try {

pstmt.close(); //사용 객체 닫음

d.conn.close(); //사용 객체 닫음

}catch(Exception e) {

e.printStackTrace();

}

}

}

//회원가입 - 네이버

public void insertMemberApi2(String id) {

d.getCon(); //데이터베이스 연결


try {

String sql = "insert into member (id,name,email,connecttype ) values (?,?,?,?)";

pstmt = d.conn.prepareStatement(sql);


pstmt.setString(1, id);

pstmt.setString(2, "네이버로그인");

pstmt.setString(3, id);

pstmt.setString(4, "네이버");


pstmt.executeUpdate();

}catch(Exception e) {

e.printStackTrace();

}finally {

try {

pstmt.close(); //사용 객체 닫음

d.conn.close(); //사용 객체 닫음

}catch(Exception e) {

e.printStackTrace();

}

}

}

}


추천0

댓글목록

등록된 댓글이 없습니다.

회원로그인

회원가입

사이트 정보

공지사항
자유게시판
질문답변
1:1문의

 

별명 : 터푸가위
주소 : 부산시 동래구 명장로20번길 90
대표 : 박규태
메일 : dancepkt@******.com

접속자집계

오늘
72
어제
172
최대
10,760
전체
264,478
Copyright © dancePKT . All rights reserved.