반응형 [DBMS]34 [Oracle]DBCP 예시 https://commons.apache.org/proper/commons-dbcp/download_dbcp.cgi lib에 추가 package home.beans; import java.sql.Connection; import java.sql.DriverManager; import javax.naming.Context; import javax.naming.InitialContext; import javax.sql.DataSource; public class JdbcUtils { //연결 생성 (1) : 직접 연결을 수행하는 방법 //- 다수의 사용자가 몰릴 경우 연결 생성 시간이 과다하여 부하로 인한 오류발생 public static Connection connect(String username,.. 2022. 5. 31. [Oracle]jdbc,beans,select Select = 조회구문 Select * from eaxm / exam의 테이블을 모두 보여주세요 ! 매개변수 = 없음 // 위구문에서 위치홀더 '?' 가없다면 매개변수가 필요없다. 메소드 작성 양식은 접근제한자 반환형 이름(매개변수) public List select() throws Exception{ public List select() throws Exception{ Connection con = JdbcUtils.connect(USERNAME, PASSWORD); String sql = "select * from exam"; PreparedStatement ps = con.prepareStatement(sql); ResultSet rs =ps.executeQuery(); ★Result rs.. 2022. 5. 31. [Oracle]Jdbc,beans,delete 업데이트와 비슷한구문이있지만 차이점을주자면 내가 특정 번호를 받아서 그특정번호에 데이터를 지우길 원한다면 굳이 DTO를 받아와야하는가? 그럴필요가 없기 떄문에 특정 번호만 불러올수 잇도록 클래스를 구성한다. public boolean delete(int exam_id) throws Exception{ Connection con =JdbcUtils.connect(USERNAME, PASSWORD); String sql="delete exam where exam_id= ?"; PreparedStatement ps = con.prepareStatement(sql); ps.setInt(1,exam_id); int result =ps.executeUpdate(); con.close(); return res.. 2022. 5. 31. [Oracle] jdbc,bean,update //[2] 수정메소드 //준비물(매개변수)examDto //결과물 반환형 : boolean public boolean update(ExamDto examDto) throws Exception{ Connection con = JdbcUtils.connect(USERNAME, PASSWORD); String sql = "update exam set Student =?,subject=? ,type=?,score=? where exam_id=?"; PreparedStatement ps = con.prepareStatement(sql); ps.setString(1, examDto.getStudent()); ps.setString(2, examDto.getSubject()); ps.setString(3, examD.. 2022. 5. 31. 이전 1 2 3 4 ··· 9 다음 반응형