dao/CategoryDAO.java > MODEL2

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

MODEL2

dao/CategoryDAO.java

페이지 정보

profile_image
작성자 관리자
댓글 0건 조회 526회 작성일 23-03-19 10:59

본문

package dao;


import java.sql.PreparedStatement;

import java.sql.ResultSet;

import java.sql.Statement;

import java.util.ArrayList;


import model.Category;

import model.Member;


public class CategoryDAO {


Statement stmt;

PreparedStatement pstmt;

ResultSet rs;


DAO d = new DAO();


//총 수

public int getAllcount(String field, String search) {

d.getCon();


int count = 0;


try {

String sql = "";


if(search != null && !search.equals("")) {

sql = "select count(*) from category where "+field+" like '%"+search+"%'";

}else {

sql = "select count(*) from category";

}


stmt = d.conn.createStatement();


rs = stmt.executeQuery(sql);


if(rs.next()) {

count = rs.getInt(1);

}

}catch(Exception e) {

e.printStackTrace();

}finally {

try {

stmt.close();

d.conn.close();

}catch(Exception e) {

e.printStackTrace();

}

}

return count;

}


//목록

public ArrayList<Category> getAllMember(int startRow, int endRow, String field, String search) {

d.getCon();


ArrayList<Category> v = new ArrayList<Category>();


try {

String sql = "";


if(search != null && !search.equals("")) {

sql = "select * from category where "+field+" like '%"+search+"%' order by ca_id asc limit ?,?";

}else {

sql = "select * from category order by ca_id asc limit ?,?";

}


pstmt = d.conn.prepareStatement(sql);


pstmt.setInt(1, startRow);

pstmt.setInt(2, endRow);


rs = pstmt.executeQuery();


while(rs.next()) {

Category c = new Category();


c.setCa_id(rs.getString("ca_id"));

c.setCa_name(rs.getString("ca_name"));

c.setCa_use(rs.getString("ca_use"));


v.add(c);

}

}catch(Exception e) {

e.printStackTrace();

}finally {

try {

rs.close();

pstmt.close();

d.conn.close();

}catch(Exception e) {

e.printStackTrace();

}

}

return v;

}


//등록

public void insertCategory(Category c) {

d.getCon();


try {

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

pstmt = d.conn.prepareStatement(sql);


pstmt.setString(1, c.getCa_id());

pstmt.setString(2, c.getCa_name());

pstmt.setString(3, c.getCa_use());


pstmt.executeUpdate();

}catch(Exception e) {

e.printStackTrace();

}finally {

try {

pstmt.close();

d.conn.close();

}catch(Exception e) {

e.printStackTrace();

}

}

}


//상세 생략

//수정

public void updateCategory(Category c) {

d.getCon();


try {

String sql = "update category set ca_name=?,ca_use=? where ca_id=?";

pstmt = d.conn.prepareStatement(sql);


pstmt.setString(1, c.getCa_name());

pstmt.setString(2, c.getCa_use());

pstmt.setString(3, c.getCa_id());


pstmt.executeUpdate();

}catch(Exception e) {

e.printStackTrace();

}finally {

try {

pstmt.close();

d.conn.close();

}catch(Exception e) {

e.printStackTrace();

}

}

}


//삭제

public void oneDelete(String ca_id) {

d.getCon();


try {

String sql = "delete from category where ca_id=?";

pstmt = d.conn.prepareStatement(sql);


pstmt.setString(1, ca_id);


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

접속자집계

오늘
136
어제
113
최대
10,760
전체
265,597
Copyright © dancePKT . All rights reserved.