[ 조회 처리 메서드 구현 ]
1) Emp vo 생성
2) 조회를 위한 메서드 제작
public void empList() {
try {
//1. 연결공통메서드 호출
setConn();
//2. Statement 객체 생성
stmt=con.createStatement();
// try{setConn(); stmt=con.createStatement까지 입력하고 왼쪽 누르면
// try/catch 나옴 }
String sql = "SELECT * FROM EMP";
//3. ResultSet 객체 생성. sql 의 결과
rs=stmt.executeQuery(sql);
//4. while() sql문의 결과 처리
// rs.next() 행 단위로 이동 처리
int rowNum =1;
while(rs.next()) {
System.out.print(rowNum+++"행");
//rs.get 데이터유형("컬럼명")
System.out.print(rs.getInt("empno")+"\t");
System.out.print(rs.getString("ename")+"\t");
System.out.print(rs.getString("job")+"\t");
System.out.print(rs.getInt("mgr")+"\t");
System.out.print(rs.getDate("hiredate")+"\t");
System.out.print(rs.getDouble("sal")+"\t");
System.out.print(rs.getDouble("comm")+"\t");
System.out.println(rs.getInt("deptno")+"\t");
}
//5. 자원해제
rs.close();
stmt.close();
con.close();
} catch (SQLException e) {
System.out.println(e.getMessage());
if(rs!=null) rs = null;
if(stmt!=null) stmt=null;
if(con!=null) con=null;
}
}
3) 객체 생성 및 메서드 처리
객체를 생성하고, 메서드를 불러와 데이터를 확인한다.
public static void main(String[] args) {
// TODO Auto-generated method stub
A02_DatabaseDao dao = new A02_DatabaseDao();
dao.empList();
}
4) 조회 결과
엉성하긴한데, 뭔가 하고있긴 하는 중 ..
'공부 > JAVA' 카테고리의 다른 글
2022.01.25 - spring 시작! (0) | 2022.01.25 |
---|---|
2022.01.06 - ORACLE / JAVA / JSP 화면출력 (0) | 2022.01.07 |
2022.01.06 - ORACLE / JAVA 연동 (0) | 2022.01.06 |
2021.12.30 - java 2회차.. 찐 답답.. (0) | 2021.12.30 |
2021.11.02 - 국비수업 java 4일차 (0) | 2021.11.07 |