db.properties 파일 생성
#property=value
url=jdbc:oracle:thin:@localhost:1521:xe //접속 주소
user=GD // 계정이름
password=1111 //비밀번호
sql 테이블 준비(GD.sql 파일)
DROP SEQUENCE USER_SEQ;
CREATE SEQUENCE USER_SEQ ORDER;
DROP TABLE USER_T;
CREATE TABLE USER_T (
USER_NO NUMBER NOT NULL
, USER_ID VARCHAR2(30 BYTE) NOT NULL UNIQUE
, USER_NAME VARCHAR2(30 BYTE)
, JOINED_AT DATE
, CONSTRAINT PK_USER PRIMARY KEY(USER_NO)
);
SELECT *FROM USER_T;
DB_Connect 클래스
package connect;
import java.io.BufferedReader;
import java.io.FileReader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Properties;
public class DB_Connect {
public static Connection getConnection() {//클래스 메소드 ,new 없이 호출가능
Connection con =null;
try (BufferedReader reader =new BufferedReader(new FileReader("src/db.properties")))
{
Class.forName("oracle.jdbc.OracleDriver");
// 프로퍼티파일 -> 프로퍼티객체
Properties p =new Properties();
p.load(reader);
con=DriverManager.getConnection(p.getProperty("url"),p.getProperty("user"),p.getProperty("password"));
}
catch (Exception e) {
}
return con;
}
}
UserDto클래스
package dto;
public class ContactDto {
private int contact_no;
private String name;
private String tel;
private String email;
private String address;
private String created_at;
public ContactDto() {
}
public ContactDto(int contact_no, String name, String tel, String email, String address, String created_at) {
super();
this.contact_no = contact_no;
this.name = name;
this.tel = tel;
this.email = email;
this.address = address;
this.created_at = created_at;
}
public int getContact_no() {
return contact_no;
}
public void setContact_no(int contact_no) {
this.contact_no = contact_no;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getTel() {
return tel;
}
public void setTel(String tel) {
this.tel = tel;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getCreated_at() {
return created_at;
}
public void setCreated_at(String created_at) {
this.created_at = created_at;
}
@Override
public String toString() {
return "ContactDto [contact_no=" + contact_no + ", name=" + name + ", tel=" + tel + ", email=" + email
+ ", address=" + address + ", created_at=" + created_at + "]";
}
}
package ex02_insert;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.Scanner;
import connect.DB_Connect;
import dto.UserDto;
public class MainWrapper {
public static void main(String[] args) {
//User 정보 입력
Scanner sc = new Scanner(System.in);
System.out.println("USER_ID>>>");
String user_id=sc.next();
sc.nextLine();
System.out.println("USER_NAME >>>");
String user_name=sc.nextLine();
sc.close();
//UserDto 생성
UserDto user = new UserDto();
user.setUser_id(user_id);
user.setUser_name(user_name);
// Connection 객체 선언(DB 접속)
Connection con =null;
// PreparedStatement 객체 선언(쿼리문 실행)
PreparedStatement ps=null;
try {
// Connection 객체 생성(DB_Connect 클래스의 getConnection 메소드로부터 받아오기)
con=DB_Connect.getConnection();
//쿼리문
String sql = "";
sql+= "INSERT INTO USER_T(USER_NO,USER_ID,USER_NAME,JOINED_AT) ";
sql+= "VALUES(USER_SEQ.NEXTVAL,?,?,SYSDATE)";//변수가 들어갈 자리는 ? 넣는게 약속
//쿼리문 뒤에 ; 세미콜론 붙이면 안됨! 구문오류남
// PreparedStatement 객체 생성
ps = con.prepareStatement(sql);
// 쿼리문에 변수 넣기
ps.setString(1, user.getUser_id());//1번째 물음표 <- user.getUser_id()
ps.setString(2,user.getUser_name());//2번째 물음표 <- user.getUser_name()
//쿼리문 실행 : insert 된 행의 개수가 반환된다.
int insertResult = ps.executeUpdate();
// 결과
System.out.println(insertResult + "개의 행이 삽입되었습니다.");
//커밋은 안한다.
//con.setAutoCommit(true); <- 기본값으로 사용되고 있다.
}catch (Exception e) {
e.printStackTrace();
}finally {
try {
if(ps!=null)ps.close();
if(con!=null)con.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
package eX03_update;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.Scanner;
import connect.DB_Connect;
import dto.UserDto;
public class MainWrapper {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
System.out.print("수정할 USER_NO>>>");
int user_no=sc.nextInt();
sc.nextLine();
System.out.print("수정할 USER_NAME>>>");
String user_name=sc.next();
sc.close();
//USER_DTO 생성
UserDto user =new UserDto();
user.setUser_no(user_no);
user.setUser_name(user_name);
//접속
Connection con =null;
//prepared 객체 선언
PreparedStatement ps =null;
try {
con=DB_Connect.getConnection();
//쿼리문
String sql="";
sql+="UPDATE USER_T";
sql+=" SET USER_NAME=?";
sql+=" WHERE USER_NO=?";
ps=con.prepareStatement(sql);
ps.setString(1, user.getUser_name());
ps.setInt(2,user.getUser_no());
int updateResult=ps.executeUpdate();
//결과
System.out.println(updateResult+"개의 행이 수정되었습니다.");
}
catch (Exception e) {
e.printStackTrace();
}try {
if(ps!=null)ps.close();
if(con!=null)con.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
package ex04_delete;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.Scanner;
import connect.DB_Connect;
import dto.UserDto;
public class MainWrapper {
public static void main(String[] args) {
//삭제할 User 정보 입력
Scanner sc =new Scanner(System.in);
System.out.println("삭제할 USER_NO>>>");
int user_no=sc.nextInt();
sc.close();
//UserDto 생성
UserDto user = new UserDto();
user.setUser_no(user_no);
Connection con =null;
PreparedStatement ps =null;
try {
con=DB_Connect.getConnection();
//쿼리
String sql="";
sql+="DELETE FROM USER_T";
sql+=" WHERE USER_NO=?";
ps=con.prepareStatement(sql);
//쿼리문에 변수 넣기
ps.setInt(1, user.getUser_no());
int deleteResult=ps.executeUpdate();
System.out.println(deleteResult+"개의 행이 삭제되었습니다.");
}catch (Exception e) {
e.printStackTrace();
}finally {
try {
if(ps!=null)ps.close();
if(con!=null)con.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
조회 결과 행이 1개인 경우
package ex05_select;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Scanner;
import connect.DB_Connect;
import dto.UserDto;
public class Ex01_selectOne {
// select 결과 행이 1개(0개)인 경우
public static void main(String[] args) {
// 조회할 사용자 번호(USER_NO) 입력
Scanner sc = new Scanner(System.in);
System.out.print("조회할 USER_NO >>> ");
int user_no = sc.nextInt();
sc.close();
// Connection 객체 선언 (DB 접속)
Connection con = null;
// PreparedStatement 객체 선언 (쿼리문 실행)
PreparedStatement ps = null;
// ResultSet 객체 선언 (검색 결과 처리)
ResultSet rs = null;
try {
// Connection 객체 생성 (DB_Connect 클래스의 getConnection 메소드로부터 받아오기)
con = DB_Connect.getConnection();
// 쿼리문
String sql = "";
sql += "SELECT USER_NO, USER_ID, USER_NAME, JOINED_AT";
sql += " FROM USER_T";
sql += " WHERE USER_NO = ?";
// PreparedStatement 객체 생성
ps = con.prepareStatement(sql);
// 쿼리문에 변수 넣기
ps.setInt(1, user_no); // 1번째 물음표 ← user_no
// 쿼리문 실행
rs = ps.executeQuery();
// 검색 결과를 저장할 UserDto 객체 선언
UserDto user = null;
// 검색 결과 행이 1개인 경우 if문을 이용해서 검색 결과가 존재하는지 1번만 체크한다.
if(rs.next()) {
// 검색 결과 행 → UserDto 객체 생성
user = new UserDto();
user.setUser_no(rs.getInt("USER_NO"));
user.setUser_id(rs.getString("USER_ID"));
user.setUser_name(rs.getString("USER_NAME"));
user.setJoined_at(rs.getDate("JOINED_AT"));
}
// 검색 결과 확인
System.out.println(user);
* rs.getInt("USER_NO") rs.getString("USER_ID") rs.getString("USER_NAME") rs.getDate("JOINED_AT")
* rs.getInt(1) rs.getString(2) rs.getString(3) rs.getDate(4)
*/
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if(rs != null) rs.close();
if(ps != null) ps.close();
if(con != null) con.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
조회 결과가 여러개인 경우
package ex05_select;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import connect.DB_Connect;
import dto.UserDto;
public class Ex02_selectList {
// select 결과 행이 여러 개인 경우
public static void main(String[] args) {
// Connection 객체 선언 (DB 접속)
Connection con = null;
// PreparedStatement 객체 선언 (쿼리문 실행)
PreparedStatement ps = null;
// ResultSet 객체 선언 (검색 결과 처리)
ResultSet rs = null;
try {
// Connection 객체 생성 (DB_Connect 클래스의 getConnection 메소드로부터 받아오기)
con = DB_Connect.getConnection();
// 쿼리문
String sql = "";
sql += "SELECT USER_NO, USER_ID, USER_NAME, JOINED_AT";
sql += " FROM USER_T";
sql += " ORDER BY USER_NO";
// PreparedStatement 객체 생성
ps = con.prepareStatement(sql);
// 쿼리문 실행
rs = ps.executeQuery();
// 검색 결과를 저장할 List<UserDto> 생성
List<UserDto> users = new ArrayList<UserDto>();
// 검색 결과가 여러 개인 경우 while문을 이용해서 검색 결과가 있는지 여러 번 체크한다.
while(rs.next()) {
// 검색 결과 행(Row) 1개 → UserDto 객체 생성
UserDto user = new UserDto();
user.setUser_no(rs.getInt(1));
user.setUser_id(rs.getString(2));
user.setUser_name(rs.getString(3));
user.setJoined_at(rs.getDate(4));
// UserDto 객체 -> List<UserDto> 추가
users.add(user);
}
// 검색 결과 확인
for(UserDto user : users) {
System.out.println(user);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if(rs != null) rs.close();
if(ps != null) ps.close();
if(con != null) con.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
ContactMain
package main;
import java.util.Map;
import javax.swing.JOptionPane;
import controller.ContactController;
import view.DeleteView;
import view.DetailView;
import view.InsertView;
import view.ListView;
import view.UpdateView;
import view.View;
// ContactMain -> ContactController -> ContactService -> ContactDao -> DB
public class ContactMain {
public static void main(String[] args) {
ContactController contactController = new ContactController();
while(true) {
String choice = JOptionPane.showInputDialog("1.삽입\n2.수정\n3.삭제\n4.전체조회\n5.상세조회\n0.종료\n원하는 작업을 입력하세요.");
View view = null;
switch(choice) {
case "1":
view = new InsertView();
break;
case "2":
view = new UpdateView();
break;
case "3":
view = new DeleteView();
break;
case "4":
view = new ListView();
break;
case "5":
view = new DetailView();
break;
case "0":
JOptionPane.showMessageDialog(null, "연락처 프로그램을 종료합니다.");
return;
default:
JOptionPane.showMessageDialog(null, "잘못된 입력입니다. 다시 선택하세요.");
}
if(view != null) {
Map<String, Object> map = view.display();
String message = contactController.request(choice, map);
JOptionPane.showMessageDialog(null, message);
}
}
}
}
ContactController
package controller;
import java.util.List;
import java.util.Map;
import dto.ContactDto;
import service.ContactService;
import service.ContactServiceImpl;
// ContactMain -> ContactController -> ContactService -> ContactDao -> DB
public class ContactController {
private ContactService contactService = new ContactServiceImpl();
/**
* 요청 처리 메소드<br>
* @param choice 1,2,3,4,5 중 하나
* @param map 사용자가 입력한 값
* choice == 1 : name, tel, email, address
* choice == 2 : contact_no, name, tel, email, address
* choice == 3 : contact_no
* choice == 4 : null
* choice == 5 : contact_no
* @return message 처리 결과 메시지
*/
public String request(String choice, Map<String, Object> map) {
System.out.println("Controller::" + map);
String message = "";
switch(choice) {
case "1":
int insertCount = contactService.insert(map);
message = insertCount + "개 연락처가 등록되었습니다.";
break;
case "2":
int updateCount = contactService.update(map);
message = updateCount + "개 연락처가 수정되었습니다.";
break;
case "3":
int deleteCount = contactService.delete(map);
message = deleteCount + "개 연락처가 삭제되었습니다.";
break;
case "4":
List<ContactDto> list = contactService.selectList();
for(ContactDto contactDto : list) {
message += contactDto.toString() + "\n";
}
break;
case "5":
ContactDto contactDto = contactService.selectContactByNo(map);
if(contactDto == null) {
message = "조회된 결과가 없습니다.";
} else {
message = "조회결과: " + contactDto.toString();
}
break;
}
return message;
}
}
ConatcatService
package service;
import java.util.List;
import java.util.Map;
import dto.ContactDto;
public interface ContactService {
int insert(Map<String, Object> map);
int update(Map<String, Object> map);
int delete(Map<String, Object> map);
List<ContactDto> selectList();
ContactDto selectContactByNo(Map<String, Object> map);
}
ContactServiceImpl
package dto;
public class ContactDto {
private int contact_no;
private String name;
private String tel;
private String email;
private String address;
private String created_at;
public ContactDto() {
}
public ContactDto(int contact_no, String name, String tel, String email, String address, String created_at) {
super();
this.contact_no = contact_no;
this.name = name;
this.tel = tel;
this.email = email;
this.address = address;
this.created_at = created_at;
}
public int getContact_no() {
return contact_no;
}
public void setContact_no(int contact_no) {
this.contact_no = contact_no;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getTel() {
return tel;
}
public void setTel(String tel) {
this.tel = tel;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getCreated_at() {
return created_at;
}
public void setCreated_at(String created_at) {
this.created_at = created_at;
}
@Override
public String toString() {
return "ContactDto [contact_no=" + contact_no + ", name=" + name + ", tel=" + tel + ", email=" + email
+ ", address=" + address + ", created_at=" + created_at + "]";
}
}
1.데이터 계층간 교환을 하기 위해 사용하는 객체로, 로직을 갖지 않는 순수한 데이터 객체(Java Beans)
2. getter/setter 메서드만 가진 클래스를 의미
3. DB데이터를 얻어서 Service나 Controller 등으로 보낼 때 사용
4. 데이터 전송객체, 데이터를 효율적으로 전송하기 위한 것
ContactDto
package dto;
public class ContactDto {
private int contact_no;
private String name;
private String tel;
private String email;
private String address;
private String created_at;
public ContactDto() {
}
public ContactDto(int contact_no, String name, String tel, String email, String address, String created_at) {
super();
this.contact_no = contact_no;
this.name = name;
this.tel = tel;
this.email = email;
this.address = address;
this.created_at = created_at;
}
public int getContact_no() {
return contact_no;
}
public void setContact_no(int contact_no) {
this.contact_no = contact_no;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getTel() {
return tel;
}
public void setTel(String tel) {
this.tel = tel;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getCreated_at() {
return created_at;
}
public void setCreated_at(String created_at) {
this.created_at = created_at;
}
@Override
public String toString() {
return "ContactDto [contact_no=" + contact_no + ", name=" + name + ", tel=" + tel + ", email=" + email
+ ", address=" + address + ", created_at=" + created_at + "]";
}
}
ContactDao
package dao;
import java.io.BufferedReader;
import java.io.FileReader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import dto.ContactDto;
// ContactMain -> ContactController -> ContactService -> ContactDao -> DB
public class ContactDao {
/*
* Singleton Pattern
* 1. 오직 하나의 객체만 만들 수 있도록 처리하는 패턴이다.
* 2. 미리 하나의 객체를 만든 뒤 해당 객체를 가져다 사용할 수 있도록 처리한다.
* 3. 객체 생성이 불가능하도록 생성자를 호출할 수 없게 만든다.
*/
private static ContactDao dao = new ContactDao();
private ContactDao() {
// 내부에서만 호출할 수 있는 생성자
}
public static ContactDao getDao() {
return dao;
}
private Connection con;
private PreparedStatement ps;
private ResultSet rs;
private Connection getConnection() {
try {
Class.forName("oracle.jdbc.OracleDriver");
Properties p = new Properties();
p.load(new BufferedReader(new FileReader("src/db.properties")));
con = DriverManager.getConnection(p.getProperty("url"), p.getProperty("user"), p.getProperty("password"));
} catch (Exception e) {
e.printStackTrace();
}
return con;
}
private void close() {
try {
if(rs != null) rs.close();
if(ps != null) ps.close();
if(con != null) con.close();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 삽입 메소드<br>
* @param contactDto 삽입할 연락처 정보(name, tel, email, address)
* @return insertCount 삽입된 행(Row)의 개수, 1이면 삽입 성공, 0이면 삽입 실패
*/
public int insert(ContactDto contactDto) {
System.out.println("Dao::" + contactDto);
int insertCount = 0;
try {
con = getConnection();
String sql = "INSERT INTO CONTACT_T(CONTACT_NO, NAME, TEL, EMAIL, ADDRESS, CREATED_AT) VALUES(CONTACT_SEQ.NEXTVAL, ?, ?, ?, ?, TO_CHAR(SYSDATE, 'YYYY-MM-DD HH24:MI:SS'))";
ps = con.prepareStatement(sql);
ps.setString(1, contactDto.getName());
ps.setString(2, contactDto.getTel());
ps.setString(3, contactDto.getEmail());
ps.setString(4, contactDto.getAddress());
insertCount = ps.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
} finally {
close();
}
return insertCount;
}
/**
* 수정 메소드<br>
* @param contactDto 수정할 연락처 정보(contact_no, name, tel, email, address)
* @return updateCount 수정된 행(Row)의 개수, 1이면 수정 성공, 0이면 수정 실패
*/
public int update(ContactDto contactDto) {
System.out.println("Dao::" + contactDto);
int updateCount = 0;
try {
con = getConnection();
String sql = "UPDATE CONTACT_T SET NAME = ?, TEL = ?, EMAIL = ?, ADDRESS = ? WHERE CONTACT_NO = ?";
ps = con.prepareStatement(sql);
ps.setString(1, contactDto.getName());
ps.setString(2, contactDto.getTel());
ps.setString(3, contactDto.getEmail());
ps.setString(4, contactDto.getAddress());
ps.setInt(5, contactDto.getContact_no());
updateCount = ps.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
} finally {
close();
}
return updateCount;
}
/**
* 삭제 메소드<br>
* @param contact_no 삭제할 연락처 번호
* @return deleteCount 삭제된 행(Row)의 개수, 1이면 삭제 성공, 0이면 삭제 실패
*/
public int delete(int contact_no) {
System.out.println("Dao::" + contact_no);
int deleteCount = 0;
try {
con = getConnection();
String sql = "DELETE FROM CONTACT_T WHERE CONTACT_NO = ?";
ps = con.prepareStatement(sql);
ps.setInt(1, contact_no);
deleteCount = ps.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
} finally {
close();
}
return deleteCount;
}
/**
* 전체 조회 메소드<br>
* @return 조회된 모든 연락처 정보(ContactDto)
*/
public List<ContactDto> selectList() {
List<ContactDto> list = new ArrayList<ContactDto>();
try {
con = getConnection();
String sql = "SELECT CONTACT_NO, NAME, TEL, EMAIL, ADDRESS, CREATED_AT FROM CONTACT_T ORDER BY CONTACT_NO ASC";
ps = con.prepareStatement(sql);
rs = ps.executeQuery();
while(rs.next()) {
ContactDto contactDto = new ContactDto();
contactDto.setContact_no(rs.getInt("CONTACT_NO"));
contactDto.setName(rs.getString("NAME"));
contactDto.setTel(rs.getString("TEL"));
contactDto.setEmail(rs.getString("EMAIL"));
contactDto.setAddress(rs.getString("ADDRESS"));
contactDto.setCreated_at(rs.getString("CREATED_AT"));
list.add(contactDto);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
close();
}
return list;
}
/**
* 상세 조회 메소드<br>
* @param contact_no 조회할 연락처 번호
* @return contactDto 조회된 연락처 정보, 조회된 연락처가 없으면 null 반환
*/
public ContactDto selectContactByNo(int contact_no) {
System.out.println("Dao::" + contact_no);
ContactDto contactDto = null;
try {
con = getConnection();
String sql = "SELECT CONTACT_NO, NAME, TEL, EMAIL, ADDRESS, CREATED_AT FROM CONTACT_T WHERE CONTACT_NO = ?";
ps = con.prepareStatement(sql);
ps.setInt(1, contact_no);
rs = ps.executeQuery();
if(rs.next()) {
contactDto = new ContactDto();
contactDto.setContact_no(rs.getInt(1));
contactDto.setName(rs.getString(2));
contactDto.setTel(rs.getString(3));
contactDto.setEmail(rs.getString(4));
contactDto.setAddress(rs.getString(5));
contactDto.setCreated_at(rs.getString(6));
}
} catch (Exception e) {
e.printStackTrace();
} finally {
close();
}
return contactDto;
}
}
View
package view;
import java.util.Map;
public interface View {
Map<String, Object> display();
}
DeleteView
package view;
import java.util.HashMap;
import java.util.Map;
import javax.swing.JOptionPane;
public class DeleteView implements View {
@Override
public Map<String, Object> display() {
if(JOptionPane.showConfirmDialog(null, "삭제를 진행할까요?") == 0) {
String contact_no = JOptionPane.showInputDialog("삭제할 연락처 번호를 입력하세요");
Map<String, Object> map = new HashMap<String, Object>();
map.put("contact_no", contact_no);
return map;
} else {
return null;
}
}
}
DetailView
package view;
import java.util.HashMap;
import java.util.Map;
import javax.swing.JOptionPane;
public class DetailView implements View {
@Override
public Map<String, Object> display() {
String contact_no = JOptionPane.showInputDialog("조회할 연락처 번호를 입력하세요");
Map<String, Object> map = new HashMap<String, Object>();
map.put("contact_no", contact_no);
return map;
}
}
InsertView
package view;
import java.util.HashMap;
import java.util.Map;
import javax.swing.JOptionPane;
public class InsertView implements View {
@Override
public Map<String, Object> display() {
String name = JOptionPane.showInputDialog("이름을 입력하세요");
String tel = JOptionPane.showInputDialog("전화번호를 입력하세요");
String email = JOptionPane.showInputDialog("이메일을 입력하세요");
String address = JOptionPane.showInputDialog("주소를 입력하세요");
Map<String, Object> map = new HashMap<String, Object>();
map.put("name", name);
map.put("tel", tel);
map.put("email", email);
map.put("address", address);
return map;
}
}
ListView
package view;
import java.util.Map;
import javax.swing.JOptionPane;
public class ListView implements View {
@Override
public Map<String, Object> display() {
JOptionPane.showMessageDialog(null, "전체 연락처를 가져옵니다.");
return null;
}
}
UpdateView
package view;
import java.util.HashMap;
import java.util.Map;
import javax.swing.JOptionPane;
public class UpdateView implements View {
@Override
public Map<String, Object> display() {
String contact_no = JOptionPane.showInputDialog("수정할 연락처 번호를 입력하세요");
String name = JOptionPane.showInputDialog("수정할 이름을 입력하세요");
String tel = JOptionPane.showInputDialog("수정할 전화번호를 입력하세요");
String email = JOptionPane.showInputDialog("수정할 이메일을 입력하세요");
String address = JOptionPane.showInputDialog("수정할 주소를 입력하세요");
Map<String, Object> map = new HashMap<String, Object>();
map.put("contact_no", contact_no);
map.put("name", name);
map.put("tel", tel);
map.put("email", email);
map.put("address", address);
return map;
}
}
db.properties
#property=value
url=jdbc:oracle:thin:@localhost:1521:xe
user=GD
password=1111
GD.sql
DROP SEQUENCE CONTACT_SEQ;
CREATE SEQUENCE CONTACT_SEQ ORDER;
DROP TABLE CONTACT_T;
CREATE TABLE CONTACT_T(
CONTACT_NO NUMBER NOT NULL
, NAME VARCHAR2(100 BYTE) NOT NULL
, TEL VARCHAR2(100 BYTE) NULL
, EMAIL VARCHAR2(100 BYTE) NULL
, ADDRESS VARCHAR2(100 BYTE) NULL
, CONSTRAINT PK_CONTACT PRIMARY KEY(CONTACT_NO)
, CREATED_AT VARCHAR2(100 BYTE) NOT NULL
);
SELECT * FROM CONTACT_T;
SELECT TO_CHAR(SYSDATE,'YYYY-MM-DD HH24:MI:SS')
FROM DUAL;
감사합니다. 이런 정보를 나눠주셔서 좋아요.