반응형
프로젝트 수행 시 선행 조건
이론 <-> 코딩(X)
필요한 것이 무엇이고 내가 다 이해했는가?
1. String(StringBuffer / StringBuilder)
2. 배열 / List / Set / Map
3. File / BufferedReader / BufferedWriter
* scanner / system.in
4. Datebase
* OOP(x) - 추상화클래스 등 이런거는 다 짜놓고 나서 최적화 작업할 때 수행해야 한다. 물론 경험이 많고 익숙하면 첨부터 가능하겠지만 지금 레벨에서는 지양한다.
MemberMgr
com.exam.MemberManagement
메소드를 만들고 -> 구조를 만들고
package com.exam;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Scanner;
public class MemberManagement {
public ArrayList<Emp> selectMember() {
//System.out.println("selectMember()");
String url = "jdbc:oracle:thin:@192.168.0.19:1521:orcl";
String user = "scott";
String password = "tiger";
PreparedStatement pstmt = null;
Connection conn = null;
ResultSet rs = null;
ArrayList<Emp> empList = new ArrayList<>();
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection(url, user, password);
String sql = "select empno, ename, job, mgr, hiredate, sal, comm, deptno from emp";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
while(rs.next()) {
Emp emp = new Emp();
emp.setEmpno(rs.getString("empno"));
emp.setEname(rs.getString("ename"));
emp.setJob(rs.getString("job"));
emp.setMgr(rs.getString("mgr"));
emp.setHiredate(rs.getString("hiredate"));
emp.setSal(rs.getString("sal"));
emp.setComm(rs.getString("comm"));
emp.setDeptno(rs.getString("deptno"));
empList.add(emp);
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally {
if(rs != null) try {rs.close();} catch(SQLException e) {};
if(pstmt != null) try {pstmt.close();} catch(SQLException e) {};
if(conn != null) try {conn.close();} catch(SQLException e) {};
}
return empList;
}
public void insertMemberForm() {
System.out.println("insertMemberForm()");
}
public void insertMemberOk() {
System.out.println("insertMemberOk()");
}
public void modifyMemberForm() {
System.out.println("modifyMemberForm()");
}
public void modifyMemberOk() {
System.out.println("modifyMemberOk()");
}
public void deleteMemberForm() {
System.out.println("deleteMemberForm()");
}
public void deleteMemberOk() {
System.out.println("deleteMemberOk()");
}
public static void main(String[] args) {
while(true) {
System.out.println("");
System.out.println("1. 목록");
System.out.println("2. 등록");
System.out.println("3. 수정");
System.out.println("4. 삭제");
System.out.println("6. 종료");
System.out.println("");
System.out.print("메뉴 선택 : ");
Scanner scanner = new Scanner(System.in);
int num = scanner.nextInt();
MemberManagement mm = new MemberManagement();
switch(num) {
case 1 :
ArrayList<Emp> empList = mm.selectMember();
for(Emp emp : empList) {
System.out.printf("%s %s %s %s %s %s %s %s %n",
emp.getEmpno(),
emp.getEname(),
emp.getJob(),
emp.getMgr(),
emp.getHiredate(),
emp.getSal(),
emp.getComm(),
emp.getDeptno());
}
break;
case 2 :
mm.insertMemberForm();
break;
case 3 :
mm.modifyMemberForm();
break;
case 4 :
mm.deleteMemberForm();
break;
case 6 :
scanner.close();
System.exit(0);
break;
default :
System.out.println("잘못된 선택입니다.");
break;
}
}
}
}
package com.exam;
// beans / dto(to) / vo(value of object)
public class Emp {
private String empno;
private String ename;
private String job;
private String mgr;
private String hiredate;
private String sal;
private String comm;
private String deptno;
public String getEmpno() {
return empno;
}
public void setEmpno(String empno) {
this.empno = empno;
}
public String getEname() {
return ename;
}
public void setEname(String ename) {
this.ename = ename;
}
public String getJob() {
return job;
}
public void setJob(String job) {
this.job = job;
}
public String getMgr() {
return mgr;
}
public void setMgr(String mgr) {
this.mgr = mgr;
}
public String getHiredate() {
return hiredate;
}
public void setHiredate(String hiredate) {
this.hiredate = hiredate;
}
public String getSal() {
return sal;
}
public void setSal(String sal) {
this.sal = sal;
}
public String getComm() {
return comm;
}
public void setComm(String comm) {
this.comm = comm;
}
public String getDeptno() {
return deptno;
}
public void setDeptno(String deptno) {
this.deptno = deptno;
}
}
반응형
댓글