2016년 7월 21일 목요일

project_1

0. GUI/ UML
UseCaseDiagram
ClassDiagram
GUI Interface


1
--데이터베이스 유저생성
conn system/123456

create user project_1
identified by 123456;

--권한 부여
grant create session, create table, create sequence, create view, create procedure
to project_1;

--디렉토리 권한 부여
grant create any directory to project_1;
create directory project_1_dir as 'c:\java\project_1';

--주소테이블 생성
conn project_1/123456

 create table address(
       zipcode char(7),
       sido varchar2(6),
       gugun varchar2(27),
       dong varchar2(39),
       ri varchar(67),
       bunji varchar2(18),
       seq number(5))
  organization external(
       type oracle_loader
       default directory project_1_dir
        access parameters(
                records delimited by newline
                badfile 'BAD_project1'
                logfile 'LOG_project1'
                  fields terminated by ','(
                          zipcode char,
                          sido char,
                          gugun char,
                          dong char,
                          ri char,
                          bunji char,
                         seq char)
                 )
         location('zipcode.csv')
         )
       parallel 7
       reject limit 200;

2. GUI 틀 만들기

//한 개의 JFrame - Management class
//여러 개의 JDiallog - Member, Membership, Address, Account, Email







3
--ORA-01950: 테이블스페이스 'USERS'에 대한 권한이 없습니다
conn system/123456
alter user project_1 default tablespace users quota unlimited on users;

--멤버테이블 생성
conn project_1/123456
create table member(
 name varchar2(20),
 sex varchar2(5),
 phone varchar2(30),
 email varchar2(100),
 birthday varchar2(20),
 solar varchar2(5),
 zipcode varchar2(20),
 address1 varchar2(100),
 address2 varchar2(100),
 company varchar2(30),
 position varchar2(30),
 etc varchar2(1000),
 constraint member_primarykey primary key (name,phone));

--이메일 내용저장 테이블 생성
create table email(
 eformat long);
insert into email values('이메일 형식을 저장하세요');

--회계장부 테이블 생성
create table account(
 day date default sysdate,
 earn varchar2(50),
 spend varchar2(50),
 memo varchar2(1000));


4.최종 클래스 바뀐 것


5. Management
import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import javax.swing.JButton;
import javax.swing.table.DefaultTableModel;
import javax.swing.JScrollPane;
import javax.swing.border.TitledBorder;
import javax.swing.UIManager;
import java.awt.Color;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.IOException;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.ScrollPaneConstants;

public class Management extends JFrame {

    private JPanel contentPane;
    private JTable table;
    private JTable table_1;
    private JTextField textField;
    private JButton btnNewButton;
    private JButton btnNewButton_1;
    private JButton btnNewButton_2;
    private JScrollPane scrollPane;
    private JScrollPane scrollPane_1;
    private JButton btnNewButton_3;
    private JPanel panel;
    private JPanel panel_1;
    private JButton btnNewButton_4;

    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    Management frame = new Management();
                    frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the frame.
     */
    public Management() {
        setTitle("Mangement");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(100, 100, 823, 441);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        setContentPane(contentPane);
        contentPane.setLayout(null);
        
        panel_1 = new JPanel();
        panel_1.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "\uD68C\uC6D0\uC815\uBCF4", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
        panel_1.setBounds(276, 40, 525, 360);
        contentPane.add(panel_1);
        panel_1.setLayout(null);
        
        scrollPane = new JScrollPane();
        scrollPane.setBounds(6, 40, 513, 304);
        panel_1.add(scrollPane);
        
        table = new JTable();
        table.setAutoResizeMode( JTable.AUTO_RESIZE_OFF );
        try {
            MembershipSearch testms =new MembershipSearch();
            if(testms.datas1.size()==0){
                table.setModel(new DefaultTableModel(
                        new Object[][] {
                            {null, null, null, null, null, null, null, null, null},
                        },
                        new String[] {
                                 "-3회", "-2회", "-1회", "이름", "번호", "근무지", "직책", "이메일", "생일"
                        }
                ));
            }else{
                table.setModel(new MembershipSearch(){
                    
                    @Override
                    public boolean isCellEditable(int rowIndex, int columnIndex) {
                        // TODO Auto-generated method stub
                        return false;
                    }
    
                    @Override
                    public Class getColumnClass(int columnIndex) {
                        // TODO Auto-generated method stub
                        return super.columnTypes1[columnIndex];
                    }
    
                    @Override
                    public String getColumnName(int column) {
                        // TODO Auto-generated method stub
                        return super.columnNames1[column];
                    }
    
                    @Override
                    public int getColumnCount() throws IndexOutOfBoundsException {
                        // TODO Auto-generated method stub
                        return super.datas1.get(0).length;
                    }
    
                    @Override
                    public Object getValueAt(int arg0, int arg1) {
                        // TODO Auto-generated method stub
                        return super.datas1.get(arg0)[arg1];
                    }
                });
            }
        } catch (IOException e3) {
            // TODO Auto-generated catch block
            e3.printStackTrace();
        }
        table.getColumnModel().getColumn(0).setMaxWidth(30);
        table.getColumnModel().getColumn(1).setMaxWidth(30);
        table.getColumnModel().getColumn(2).setMaxWidth(30);
        table.getColumnModel().getColumn(3).setMinWidth(80);
        table.getColumnModel().getColumn(4).setMinWidth(100);
        table.getColumnModel().getColumn(7).setMinWidth(100);
        scrollPane.setViewportView(table);
        
        
        btnNewButton = new JButton("등록");
        btnNewButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                Member memberDialog = new Member();
                memberDialog.setVisible(true);
                try {
                    table.setModel(new MembershipSearch(){
                        
                        @Override
                        public boolean isCellEditable(int rowIndex, int columnIndex) {
                            // TODO Auto-generated method stub
                            return false;
                        }
        
                        @Override
                        public Class getColumnClass(int columnIndex) {
                            // TODO Auto-generated method stub
                            return super.columnTypes1[columnIndex];
                        }
        
                        @Override
                        public String getColumnName(int column) {
                            // TODO Auto-generated method stub
                            return super.columnNames1[column];
                        }
        
                        @Override
                        public int getColumnCount() throws IndexOutOfBoundsException {
                            // TODO Auto-generated method stub
                            return super.datas1.get(0).length;
                        }
        
                        @Override
                        public Object getValueAt(int arg0, int arg1) {
                            // TODO Auto-generated method stub
                            return super.datas1.get(arg0)[arg1];
                        }
                    });
                } catch (IOException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }
                table.getColumnModel().getColumn(0).setMaxWidth(30);
                table.getColumnModel().getColumn(1).setMaxWidth(30);
                table.getColumnModel().getColumn(2).setMaxWidth(30);
                table.getColumnModel().getColumn(3).setMinWidth(80);
                table.getColumnModel().getColumn(4).setMinWidth(100);
                table.getColumnModel().getColumn(7).setMinWidth(100);
            }
        });

        btnNewButton.setBounds(230, 17, 97, 23);
        panel_1.add(btnNewButton);
        
        btnNewButton_1 = new JButton("수정");
        btnNewButton_1.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent arg0) {
                if(table.getSelectedRow()!=-1){
                    try {
                        MembershipSearch ms = new MembershipSearch();
                        int rownum = table.getSelectedRow();
                        MemberModify membermodify = new MemberModify((String)ms.datas3.get(rownum)[0],(String)ms.datas3.get(table.getSelectedRow())[2]);
                        membermodify.textField.setText((String)ms.datas3.get(rownum)[0]);
                        if(ms.datas3.get(rownum)[1].equals("남")){ membermodify.radioButton.setSelected(true);}else{membermodify.radioButton_1.setSelected(true);}
                        membermodify.textField_1.setText((String)ms.datas3.get(table.getSelectedRow())[2]);
                        membermodify.textField_2.setText((String)ms.datas3.get(table.getSelectedRow())[3]);
                        String[] year =ms.datas3.get(table.getSelectedRow())[4].toString().split("/");
                        membermodify.comboBox.setSelectedItem(year[0]);
                        membermodify.comboBox_1.setSelectedItem(year[1]);
                        membermodify.comboBox_2.setSelectedItem(year[2]);
                        if(ms.datas3.get(rownum)[5].equals("양")){ membermodify.radioButton_2.setSelected(true);}else{membermodify.radioButton_3.setSelected(true);}
                        String[] zipcode;
                        if(!((String)ms.datas3.get(table.getSelectedRow())[6]).equals("-")){
                            zipcode =((String)ms.datas3.get(table.getSelectedRow())[6]).split("-");
                        }else{
                            zipcode =new String[]{"",""};
                        }
                        membermodify.textField_3.setText(zipcode[0]);
                        membermodify.textField_4.setText(zipcode[1]);
                        membermodify.textField_5.setText((String)ms.datas3.get(table.getSelectedRow())[7]);
                        membermodify.textField_6.setText((String)ms.datas3.get(table.getSelectedRow())[8]);
                        membermodify.textField_7.setText((String)ms.datas3.get(table.getSelectedRow())[9]);
                        membermodify.textField_8.setText((String)ms.datas3.get(table.getSelectedRow())[10]);
                        membermodify.textArea.setText((String)ms.datas3.get(table.getSelectedRow())[11]);
                        
                        membermodify.setVisible(true);
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
                try {
                    table.setModel(new MembershipSearch(){
                        
                        @Override
                        public boolean isCellEditable(int rowIndex, int columnIndex) {
                            // TODO Auto-generated method stub
                            return false;
                        }
        
                        @Override
                        public Class getColumnClass(int columnIndex) {
                            // TODO Auto-generated method stub
                            return super.columnTypes1[columnIndex];
                        }
        
                        @Override
                        public String getColumnName(int column) {
                            // TODO Auto-generated method stub
                            return super.columnNames1[column];
                        }
        
                        @Override
                        public int getColumnCount() throws IndexOutOfBoundsException {
                            // TODO Auto-generated method stub
                            return super.datas1.get(0).length;
                        }
        
                        @Override
                        public Object getValueAt(int arg0, int arg1) {
                            // TODO Auto-generated method stub
                            return super.datas1.get(arg0)[arg1];
                        }
                    });
                } catch (IOException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }
                table.getColumnModel().getColumn(0).setMaxWidth(30);
                table.getColumnModel().getColumn(1).setMaxWidth(30);
                table.getColumnModel().getColumn(2).setMaxWidth(30);
                table.getColumnModel().getColumn(3).setMinWidth(80);
                table.getColumnModel().getColumn(4).setMinWidth(100);
                table.getColumnModel().getColumn(7).setMinWidth(100);
            }
        });
        btnNewButton_1.setBounds(326, 17, 97, 23);
        panel_1.add(btnNewButton_1);
        
        btnNewButton_2 = new JButton("삭제");
        btnNewButton_2.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                String name = (String)table.getValueAt(table.getSelectedRow(), 3);
                String phone = (String)table.getValueAt(table.getSelectedRow(), 4);
                new MemberDelete(name, phone);
                
                try {
                    table.setModel(new MembershipSearch(){
                        
                        @Override
                        public boolean isCellEditable(int rowIndex, int columnIndex) {
                            // TODO Auto-generated method stub
                            return false;
                        }
        
                        @Override
                        public Class getColumnClass(int columnIndex) {
                            // TODO Auto-generated method stub
                            return super.columnTypes1[columnIndex];
                        }
        
                        @Override
                        public String getColumnName(int column) {
                            // TODO Auto-generated method stub
                            return super.columnNames1[column];
                        }
        
                        @Override
                        public int getColumnCount() throws IndexOutOfBoundsException {
                            // TODO Auto-generated method stub
                            return super.datas1.get(0).length;
                        }
        
                        @Override
                        public Object getValueAt(int arg0, int arg1) {
                            // TODO Auto-generated method stub
                            return super.datas1.get(arg0)[arg1];
                        }
                    });
                } catch (IOException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }
                table.getColumnModel().getColumn(0).setMaxWidth(30);
                table.getColumnModel().getColumn(1).setMaxWidth(30);
                table.getColumnModel().getColumn(2).setMaxWidth(30);
                table.getColumnModel().getColumn(3).setMinWidth(80);
                table.getColumnModel().getColumn(4).setMinWidth(100);
                table.getColumnModel().getColumn(7).setMinWidth(100);
            }
        });
        btnNewButton_2.setBounds(422, 17, 97, 23);
        panel_1.add(btnNewButton_2);
        table.getColumnModel().getColumn(0).setPreferredWidth(30);
        table.getColumnModel().getColumn(1).setPreferredWidth(30);
        table.getColumnModel().getColumn(2).setPreferredWidth(40);
        table.getColumnModel().getColumn(3).setPreferredWidth(40);
        table.getColumnModel().getColumn(7).setPreferredWidth(120);
        table.getColumnModel().getColumn(7).setMinWidth(120);
        
        panel = new JPanel();
        panel.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "\uD68C\uBE44\uC0AC\uC6A9\uB0B4\uC5ED", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
        panel.setBounds(6, 40, 270, 360);
        contentPane.add(panel);
        panel.setLayout(null);
        
        scrollPane_1 = new JScrollPane();
        scrollPane_1.setBounds(6, 40, 258, 258);
        panel.add(scrollPane_1);
        
        table_1 = new JTable();
        scrollPane_1.setViewportView(table_1);
        try {
            table_1.setModel(new AccountSearch(){
                
                //컬럼갯수를 오버라이드한뒤 -1을 해서 마지막 컬럼을 출력하지 않음
                @Override
                public int getColumnCount() throws IndexOutOfBoundsException {
                    return super.getColumnCount()-1;
                }

                @Override
                public int getRowCount() {
                    // TODO Auto-generated method stub
                    return super.getRowCount()-5;
                }
                
            });
        } catch (IOException e2) {
            // TODO Auto-generated catch block
            e2.printStackTrace();
        }
        
        textField = new JTextField();
        textField.setBounds(65, 308, 199, 36);
        panel.add(textField);
        textField.setHorizontalAlignment(SwingConstants.RIGHT);
        textField.setColumns(10);
        int sum=0;
        for(int i=0;i<table_1.getRowCount();i++){
            try {sum += Integer.parseInt((String)table_1.getValueAt(i, 0));} catch (NumberFormatException e) {}
            try {sum -= Integer.parseInt((String)table_1.getValueAt(i, 1));} catch (NumberFormatException e) {}
        }
        textField.setText(""+sum);
        
        JLabel label = new JLabel("총액");
        label.setBounds(6, 308, 57, 36);
        panel.add(label);
        label.setHorizontalAlignment(SwingConstants.CENTER);
        
        btnNewButton_3 = new JButton("회비등록");
        btnNewButton_3.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                try {
                    Membership membershipDialog = new Membership();
                    membershipDialog.setVisible(true);
                } catch (IndexOutOfBoundsException e1) {
                    // TODO Auto-generated catch block
                    System.out.println("데이터베이스에 값이 없습니다");
                }
                try {
                    table_1.setModel(new AccountSearch(){
                        
                        //컬럼갯수를 오버라이드한뒤 -1을 해서 마지막 컬럼을 출력하지 않음
                        @Override
                        public int getColumnCount() throws IndexOutOfBoundsException {
                            return super.getColumnCount()-1;
                        }
                        @Override
                        public int getRowCount() {
                            // TODO Auto-generated method stub
                            return super.getRowCount()-5;
                        }
                        
                    });
                } catch (IOException e2) {
                    // TODO Auto-generated catch block
                    e2.printStackTrace();
                }
                int sum=0;
                for(int i=0;i<table_1.getRowCount();i++){
                    try {sum += Integer.parseInt((String)table_1.getValueAt(i, 0));} catch (NumberFormatException e1) {}
                    try {sum -= Integer.parseInt((String)table_1.getValueAt(i, 1));} catch (NumberFormatException e1) {}
                }
                textField.setText(""+sum);
                try {
                    table.setModel(new MembershipSearch(){
                        
                        @Override
                        public boolean isCellEditable(int rowIndex, int columnIndex) {
                            // TODO Auto-generated method stub
                            return false;
                        }
        
                        @Override
                        public Class getColumnClass(int columnIndex) {
                            // TODO Auto-generated method stub
                            return super.columnTypes1[columnIndex];
                        }
        
                        @Override
                        public String getColumnName(int column) {
                            // TODO Auto-generated method stub
                            return super.columnNames1[column];
                        }
        
                        @Override
                        public int getColumnCount() throws IndexOutOfBoundsException {
                            // TODO Auto-generated method stub
                            return super.datas1.get(0).length;
                        }
        
                        @Override
                        public Object getValueAt(int arg0, int arg1) {
                            // TODO Auto-generated method stub
                            return super.datas1.get(arg0)[arg1];
                        }
                    });
                } catch (IOException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }
                table.getColumnModel().getColumn(0).setMaxWidth(30);
                table.getColumnModel().getColumn(1).setMaxWidth(30);
                table.getColumnModel().getColumn(2).setMaxWidth(30);
                table.getColumnModel().getColumn(3).setMinWidth(80);
                table.getColumnModel().getColumn(4).setMinWidth(100);
                table.getColumnModel().getColumn(7).setMinWidth(100);
            }
        });
        btnNewButton_3.setBounds(173, 17, 91, 23);
        panel.add(btnNewButton_3);
        
        btnNewButton_4 = new JButton("회계장부");
        btnNewButton_4.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent arg0) {
                Account accountDialog;
                try {
                    accountDialog = new Account();
                    accountDialog.setVisible(true);
                } catch (IndexOutOfBoundsException e) {
                    // TODO Auto-generated catch block
                    System.out.println("데이터베이스에 값이 없습니다");
                }
                try {
                    table_1.setModel(new AccountSearch(){
                        
                        //컬럼갯수를 오버라이드한뒤 -1을 해서 마지막 컬럼을 출력하지 않음
                        @Override
                        public int getColumnCount() throws IndexOutOfBoundsException {
                            return super.getColumnCount()-1;
                        }
                        @Override
                        public int getRowCount() {
                            // TODO Auto-generated method stub
                            return super.getRowCount()-5;
                        }
                        
                    });
                } catch (IOException e2) {
                    // TODO Auto-generated catch block
                    e2.printStackTrace();
                }
                int sum=0;
                for(int i=0;i<table_1.getRowCount();i++){
                    try {sum += Integer.parseInt((String)table_1.getValueAt(i, 0));} catch (NumberFormatException e) {}
                    try {sum -= Integer.parseInt((String)table_1.getValueAt(i, 1));} catch (NumberFormatException e) {}
                }
                textField.setText(""+sum);
            }
        });
        btnNewButton_4.setBounds(83, 17, 91, 23);
        panel.add(btnNewButton_4);
        
        JButton btnall = new JButton("이메일ALL");
        btnall.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                Email emailDialog = new Email();
                emailDialog.setVisible(true);
            }
        });
        btnall.setBounds(698, 10, 97, 23);
        contentPane.add(btnall);
    }
}


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class MemberDelete {
    
    public MemberDelete(String name, String phone) {
        String url = "jdbc:oracle:thin:@127.0.0.1:1521:orcl";
        String user = "project_1";
        String password = "123456";
          
        Connection conn = null;
        PreparedStatement pstmt = null;
        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            System.out.println("데이터베이스 로딩 성공");
            
            conn = DriverManager.getConnection(url, user, password);
            System.out.println("데이터베이스 연결 성공");
            
            //이름과 폰번호가 일치하는 데이터베이스 행을 수정함
                String sql_2 = "delete from member where name=? and phone=?";
                pstmt = conn.prepareStatement(sql_2);
                pstmt.setString(1, name);
                pstmt.setString(2, phone);
                pstmt.executeUpdate();
            
            System.out.println("SQL 실행 성공");
        } catch (ClassNotFoundException e) {
           // TODO Auto-generated catch block
           System.out.println("[에러] : "+e.getMessage());
        } catch (SQLException e) {
           // TODO Auto-generated catch block
           System.out.println("[에러] : "+e.getMessage());
        } finally {
           if(pstmt != null) try { pstmt.close(); } catch(SQLException e){}
           if(conn != null) try { conn.close(); } catch(SQLException e){}
        }
    }
}


import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JRadioButton;
import javax.swing.JComboBox;
import javax.swing.JTable;
import javax.swing.border.TitledBorder;
import javax.swing.plaf.basic.BasicBorders.RadioButtonBorder;
import javax.swing.UIManager;
import java.awt.Color;
import javax.swing.SwingConstants;
import javax.swing.JTextArea;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.Calendar;

import javax.swing.ButtonGroup;

public class MemberModify extends JDialog {

    private final JPanel contentPanel = new JPanel();
    public JTextField textField;
    public JTextField textField_1;
    public JTextField textField_2;
    public JTextField textField_3;
    public JTextField textField_4;
    public JTextField textField_5;
    public JTextField textField_6;
    public JTextField textField_7;
    public JTextField textField_8;
    public final ButtonGroup buttonGroup = new ButtonGroup();
    public final ButtonGroup buttonGroup_1 = new ButtonGroup();
    public JRadioButton radioButton;
    public JRadioButton radioButton_1;
    public JRadioButton radioButton_2;
    public JRadioButton radioButton_3;
    public JComboBox comboBox;
    public JComboBox comboBox_1;
    public JComboBox comboBox_2;
    public JTextArea textArea;

    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        try {
            MemberModify dialog = new MemberModify("","");
            dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
            dialog.setVisible(true);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * Create the dialog.
     */
    public MemberModify(String prename, String prephone) {
        setTitle("Member");
        setModal(true);         //이 창을 닫기전까지 부모창으로 갈 수 없음
        setResizable(false);    //사이즈 변경불가능
        setBounds(100, 100, 450, 579);
        getContentPane().setLayout(new BorderLayout());
        contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
        getContentPane().add(contentPanel, BorderLayout.CENTER);
        contentPanel.setLayout(null);
        {
            JPanel panel = new JPanel();
            panel.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "\uAE30\uBCF8\uC815\uBCF4", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
            panel.setBounds(6, 20, 416, 139);
            contentPanel.add(panel);
            panel.setLayout(null);
            {
                textField = new JTextField();
                textField.setBounds(69, 18, 123, 21);
                panel.add(textField);
                textField.setColumns(10);
            }
            {
                JLabel label = new JLabel("이 름");
                label.setBounds(6, 21, 57, 15);
                panel.add(label);
            }
            {
                JLabel label = new JLabel("전화번호");
                label.setBounds(6, 48, 57, 15);
                panel.add(label);
            }
            {
                textField_1 = new JTextField();
                textField_1.setBounds(69, 45, 322, 21);
                panel.add(textField_1);
                textField_1.setColumns(10);
            }
            {
                JLabel label = new JLabel("이메일");
                label.setBounds(6, 76, 57, 15);
                panel.add(label);
            }
            {
                textField_2 = new JTextField();
                textField_2.setBounds(69, 73, 322, 21);
                panel.add(textField_2);
                textField_2.setColumns(10);
            }
            {
                JLabel label = new JLabel("생년월일");
                label.setBounds(6, 104, 57, 15);
                panel.add(label);
            }
            {
                JLabel label = new JLabel("성 별");
                label.setBounds(250, 21, 40, 15);
                panel.add(label);
            }
            
            radioButton = new JRadioButton("남");
            buttonGroup.add(radioButton);
            radioButton.setBounds(298, 17, 40, 23);
            panel.add(radioButton);
            
            radioButton_1 = new JRadioButton("여");
            buttonGroup.add(radioButton_1);
            radioButton_1.setBounds(342, 17, 49, 23);
            panel.add(radioButton_1);
            
            JLabel label = new JLabel("음 양");
            label.setBounds(250, 104, 40, 15);
            panel.add(label);
            
            radioButton_2 = new JRadioButton("양");
            buttonGroup_1.add(radioButton_2);
            radioButton_2.setBounds(298, 100, 40, 23);
            panel.add(radioButton_2);
            
            radioButton_3 = new JRadioButton("음");
            buttonGroup_1.add(radioButton_3);
            radioButton_3.setBounds(342, 100, 49, 23);
            panel.add(radioButton_3);
            
            //년도 콤보박스 만들기
            ArrayList<String> years = new ArrayList<String>();
            for(int i = Calendar.getInstance().get(Calendar.YEAR); i>=1930 ;i--){
                years.add(i+"");
            }
            comboBox = new JComboBox(years.toArray());;
            comboBox.setBounds(69, 101, 57, 21);
            panel.add(comboBox);
            //월 콤보박스
            String[] months = {"1","2","3","4","5","6","7","8","9","10","11","12"};
            comboBox_1 = new JComboBox(months);
            comboBox_1.setBounds(136, 101, 40, 21);
            panel.add(comboBox_1);
            //일 콤보박스
            ArrayList<String> days = new ArrayList<String>();
            for(int i = 1; i<=31 ;i++){
                days.add(i+"");
            }
            comboBox_2 = new JComboBox(days.toArray());
            comboBox_2.setBounds(184, 101, 40, 21);
            panel.add(comboBox_2);
        }
        {
            JPanel panel = new JPanel();
            panel.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "\uC8FC\uC18C\uC815\uBCF4", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
            panel.setBounds(6, 170, 416, 118);
            contentPanel.add(panel);
            panel.setLayout(null);
            {
                textField_3 = new JTextField();
                textField_3.setBounds(6, 18, 73, 21);
                panel.add(textField_3);
                textField_3.setColumns(10);
            }
            {
                textField_4 = new JTextField();
                textField_4.setBounds(113, 18, 73, 21);
                panel.add(textField_4);
                textField_4.setColumns(10);
            }
            {
                textField_5 = new JTextField();
                textField_5.setBounds(6, 49, 384, 21);
                panel.add(textField_5);
                textField_5.setColumns(10);
            }
            {
                textField_6 = new JTextField();
                textField_6.setBounds(6, 80, 384, 21);
                panel.add(textField_6);
                textField_6.setColumns(10);
            }
            {
                JLabel label = new JLabel("-");
                label.setBounds(84, 21, 21, 15);
                panel.add(label);
                label.setHorizontalAlignment(SwingConstants.CENTER);
            }
            {
                JButton btnNewButton = new JButton("우편번호 검색");
                btnNewButton.addMouseListener(new MouseAdapter() {
                    @Override
                    public void mouseClicked(MouseEvent e) {
                        Address addressDialog = new Address();
                        addressDialog.setVisible(true);
                        try {
                            textField_3.setText(addressDialog.zipcode[0]);
                            textField_4.setText(addressDialog.zipcode[1]);
                            textField_5.setText(addressDialog.address);
                        } catch (NullPointerException e1) {
                            System.out.println("입력값이 없습니다");
                        }
                    }
                });
                btnNewButton.setBounds(263, 17, 127, 23);
                panel.add(btnNewButton);
            }
        }
        
        JPanel panel = new JPanel();
        panel.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "\uCD94\uAC00\uC815\uBCF4", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
        panel.setBounds(6, 305, 416, 195);
        contentPanel.add(panel);
        panel.setLayout(null);
        {
            textField_7 = new JTextField();
            textField_7.setBounds(64, 17, 163, 21);
            panel.add(textField_7);
            textField_7.setColumns(10);
        }
        {
            textField_8 = new JTextField();
            textField_8.setBounds(292, 17, 100, 21);
            panel.add(textField_8);
            textField_8.setColumns(10);
        }
        {
            JLabel label = new JLabel("근무지");
            label.setBounds(9, 20, 43, 15);
            panel.add(label);
            label.setHorizontalAlignment(SwingConstants.LEFT);
        }
        {
            JLabel label = new JLabel("직 책");
            label.setBounds(246, 20, 34, 15);
            panel.add(label);
            label.setHorizontalAlignment(SwingConstants.LEFT);
        }
        {
            JLabel label = new JLabel("기타사항");
            label.setBounds(9, 45, 57, 15);
            panel.add(label);
        }
        
        textArea = new JTextArea();
        textArea.setBounds(9, 67, 384, 116);
        panel.add(textArea);
        {
            JPanel buttonPane = new JPanel();
            buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
            getContentPane().add(buttonPane, BorderLayout.SOUTH);
            {
                JButton okButton = new JButton("수정");
                okButton.addMouseListener(new MouseAdapter() {
                    @Override
                    public void mouseClicked(MouseEvent e) {
                        //필수정보 입력확인
                        if(textField.getText().equals("")
                           || !(radioButton.isSelected() || radioButton_1.isSelected())
                           || textField_1.getText().equals("")
                           || textField_2.getText().equals("")
                           || (comboBox.getSelectedItem().equals(Calendar.getInstance().get(Calendar.YEAR)))
                           || !(radioButton_2.isSelected() || radioButton_3.isSelected())
                        ){JOptionPane.showMessageDialog(MemberModify.this, "기본정보를 입력하셔야합니다","입력오류", JOptionPane.WARNING_MESSAGE);
                        }else{
                            //데이터 베이스에 회원정보 저장
                             String name = textField.getText();
                             String sex = radioButton.isSelected()?"남":"여";
                             String phone = textField_1.getText();
                             String email = textField_2.getText();
                             String birthday = comboBox.getSelectedItem()+"/"+comboBox_1.getSelectedItem()+"/"+comboBox_2.getSelectedItem();
                             String solar = radioButton_2.isSelected()?"양":"음";
                             String zipcode = textField_3.getText()+"-"+textField_4.getText();
                             String address1 = textField_5.getText();
                             String address2 = textField_6.getText();
                             String company = textField_7.getText();
                             String position = textField_8.getText();
                             String etc = textArea.getText();
                             new MemberSave(prename, prephone, name, sex, phone, email, birthday, solar, zipcode, address1, address2, company, position, etc);
                             dispose();
                        }
                    }
                });
                okButton.setActionCommand("OK");
                buttonPane.add(okButton);
                getRootPane().setDefaultButton(okButton);
            }
            {
                JButton cancelButton = new JButton("취소");
                cancelButton.addMouseListener(new MouseAdapter() {
                    @Override
                    public void mouseClicked(MouseEvent e) {
                        dispose();
                    }
                });
                cancelButton.setActionCommand("Cancel");
                buttonPane.add(cancelButton);
            }
        }
    }
}


6.member
import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JRadioButton;
import javax.swing.JComboBox;
import javax.swing.JTable;
import javax.swing.border.TitledBorder;
import javax.swing.plaf.basic.BasicBorders.RadioButtonBorder;
import javax.swing.UIManager;
import java.awt.Color;
import javax.swing.SwingConstants;
import javax.swing.JTextArea;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.Calendar;

import javax.swing.ButtonGroup;

public class Member extends JDialog {

    private final JPanel contentPanel = new JPanel();
    public JTextField textField;
    public JTextField textField_1;
    public JTextField textField_2;
    public JTextField textField_3;
    public JTextField textField_4;
    public JTextField textField_5;
    public JTextField textField_6;
    public JTextField textField_7;
    public JTextField textField_8;
    public final ButtonGroup buttonGroup = new ButtonGroup();
    public final ButtonGroup buttonGroup_1 = new ButtonGroup();
    public JRadioButton radioButton;
    public JRadioButton radioButton_1;
    public JRadioButton radioButton_2;
    public JRadioButton radioButton_3;
    public JComboBox comboBox;
    public JComboBox comboBox_1;
    public JComboBox comboBox_2;
    public JTextArea textArea;

    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        try {
            Member dialog = new Member();
            dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
            dialog.setVisible(true);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * Create the dialog.
     */
    public Member() {
        setTitle("Member");
        setModal(true);         //이 창을 닫기전까지 부모창으로 갈 수 없음
        setResizable(false);    //사이즈 변경불가능
        setBounds(100, 100, 450, 579);
        getContentPane().setLayout(new BorderLayout());
        contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
        getContentPane().add(contentPanel, BorderLayout.CENTER);
        contentPanel.setLayout(null);
        {
            JPanel panel = new JPanel();
            panel.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "\uAE30\uBCF8\uC815\uBCF4", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
            panel.setBounds(6, 20, 416, 139);
            contentPanel.add(panel);
            panel.setLayout(null);
            {
                textField = new JTextField();
                textField.setBounds(69, 18, 123, 21);
                panel.add(textField);
                textField.setColumns(10);
            }
            {
                JLabel label = new JLabel("이 름");
                label.setBounds(6, 21, 57, 15);
                panel.add(label);
            }
            {
                JLabel label = new JLabel("전화번호");
                label.setBounds(6, 48, 57, 15);
                panel.add(label);
            }
            {
                textField_1 = new JTextField();
                textField_1.setBounds(69, 45, 322, 21);
                panel.add(textField_1);
                textField_1.setColumns(10);
            }
            {
                JLabel label = new JLabel("이메일");
                label.setBounds(6, 76, 57, 15);
                panel.add(label);
            }
            {
                textField_2 = new JTextField();
                textField_2.setBounds(69, 73, 322, 21);
                panel.add(textField_2);
                textField_2.setColumns(10);
            }
            {
                JLabel label = new JLabel("생년월일");
                label.setBounds(6, 104, 57, 15);
                panel.add(label);
            }
            {
                JLabel label = new JLabel("성 별");
                label.setBounds(250, 21, 40, 15);
                panel.add(label);
            }
            
            radioButton = new JRadioButton("남");
            buttonGroup.add(radioButton);
            radioButton.setBounds(298, 17, 40, 23);
            panel.add(radioButton);
            
            radioButton_1 = new JRadioButton("여");
            buttonGroup.add(radioButton_1);
            radioButton_1.setBounds(342, 17, 49, 23);
            panel.add(radioButton_1);
            
            JLabel label = new JLabel("음 양");
            label.setBounds(250, 104, 40, 15);
            panel.add(label);
            
            radioButton_2 = new JRadioButton("양");
            buttonGroup_1.add(radioButton_2);
            radioButton_2.setBounds(298, 100, 40, 23);
            panel.add(radioButton_2);
            
            radioButton_3 = new JRadioButton("음");
            buttonGroup_1.add(radioButton_3);
            radioButton_3.setBounds(342, 100, 49, 23);
            panel.add(radioButton_3);
            
            //년도 콤보박스 만들기
            ArrayList<String> years = new ArrayList<String>();
            for(int i = Calendar.getInstance().get(Calendar.YEAR); i>=1930 ;i--){
                years.add(i+"");
            }
            comboBox = new JComboBox(years.toArray());;
            comboBox.setBounds(69, 101, 57, 21);
            panel.add(comboBox);
            //월 콤보박스
            String[] months = {"1","2","3","4","5","6","7","8","9","10","11","12"};
            comboBox_1 = new JComboBox(months);
            comboBox_1.setBounds(136, 101, 40, 21);
            panel.add(comboBox_1);
            //일 콤보박스
            ArrayList<String> days = new ArrayList<String>();
            for(int i = 1; i<=31 ;i++){
                days.add(i+"");
            }
            comboBox_2 = new JComboBox(days.toArray());
            comboBox_2.setBounds(184, 101, 40, 21);
            panel.add(comboBox_2);
        }
        {
            JPanel panel = new JPanel();
            panel.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "\uC8FC\uC18C\uC815\uBCF4", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
            panel.setBounds(6, 170, 416, 118);
            contentPanel.add(panel);
            panel.setLayout(null);
            {
                textField_3 = new JTextField();
                textField_3.setBounds(6, 18, 73, 21);
                panel.add(textField_3);
                textField_3.setColumns(10);
            }
            {
                textField_4 = new JTextField();
                textField_4.setBounds(113, 18, 73, 21);
                panel.add(textField_4);
                textField_4.setColumns(10);
            }
            {
                textField_5 = new JTextField();
                textField_5.setBounds(6, 49, 384, 21);
                panel.add(textField_5);
                textField_5.setColumns(10);
            }
            {
                textField_6 = new JTextField();
                textField_6.setBounds(6, 80, 384, 21);
                panel.add(textField_6);
                textField_6.setColumns(10);
            }
            {
                JLabel label = new JLabel("-");
                label.setBounds(84, 21, 21, 15);
                panel.add(label);
                label.setHorizontalAlignment(SwingConstants.CENTER);
            }
            {
                JButton btnNewButton = new JButton("우편번호 검색");
                btnNewButton.addMouseListener(new MouseAdapter() {
                    @Override
                    public void mouseClicked(MouseEvent e) {
                        Address addressDialog = new Address();
                        addressDialog.setVisible(true);
                        try {
                            textField_3.setText(addressDialog.zipcode[0]);
                            textField_4.setText(addressDialog.zipcode[1]);
                            textField_5.setText(addressDialog.address);
                        } catch (NullPointerException e1) {
                            System.out.println("입력값이 없습니다");
                        }
                    }
                });
                btnNewButton.setBounds(263, 17, 127, 23);
                panel.add(btnNewButton);
            }
        }
        
        JPanel panel = new JPanel();
        panel.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "\uCD94\uAC00\uC815\uBCF4", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
        panel.setBounds(6, 305, 416, 195);
        contentPanel.add(panel);
        panel.setLayout(null);
        {
            textField_7 = new JTextField();
            textField_7.setBounds(64, 17, 163, 21);
            panel.add(textField_7);
            textField_7.setColumns(10);
        }
        {
            textField_8 = new JTextField();
            textField_8.setBounds(292, 17, 100, 21);
            panel.add(textField_8);
            textField_8.setColumns(10);
        }
        {
            JLabel label = new JLabel("근무지");
            label.setBounds(9, 20, 43, 15);
            panel.add(label);
            label.setHorizontalAlignment(SwingConstants.LEFT);
        }
        {
            JLabel label = new JLabel("직 책");
            label.setBounds(246, 20, 34, 15);
            panel.add(label);
            label.setHorizontalAlignment(SwingConstants.LEFT);
        }
        {
            JLabel label = new JLabel("기타사항");
            label.setBounds(9, 45, 57, 15);
            panel.add(label);
        }
        
        textArea = new JTextArea();
        textArea.setBounds(9, 67, 384, 116);
        panel.add(textArea);
        {
            JPanel buttonPane = new JPanel();
            buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
            getContentPane().add(buttonPane, BorderLayout.SOUTH);
            {
                JButton okButton = new JButton("추가");
                okButton.addMouseListener(new MouseAdapter() {
                    @Override
                    public void mouseClicked(MouseEvent e) {
                        //필수정보 입력확인
                        if(textField.getText().equals("")
                           || !(radioButton.isSelected() || radioButton_1.isSelected())
                           || textField_1.getText().equals("")
                           || textField_2.getText().equals("")
                           || (comboBox.getSelectedItem().equals(Calendar.getInstance().get(Calendar.YEAR)))
                           || !(radioButton_2.isSelected() || radioButton_3.isSelected())
                        ){JOptionPane.showMessageDialog(Member.this, "기본정보를 입력하셔야합니다","입력오류", JOptionPane.WARNING_MESSAGE);
                        }else{
                            //데이터 베이스에 회원정보 저장
                             String name = textField.getText();
                             String sex = radioButton.isSelected()?"남":"여";
                             String phone = textField_1.getText();
                             String email = textField_2.getText();
                             String birthday = comboBox.getSelectedItem()+"/"+comboBox_1.getSelectedItem()+"/"+comboBox_2.getSelectedItem();
                             String solar = radioButton_2.isSelected()?"양":"음";
                             String zipcode = textField_3.getText()+"-"+textField_4.getText();
                             String address1 = textField_5.getText();
                             String address2 = textField_6.getText();
                             String company = textField_7.getText();
                             String position = textField_8.getText();
                             String etc = textArea.getText();
                             new MemberSave(name, sex, phone, email, birthday, solar, zipcode, address1, address2, company, position, etc);
                             dispose();
                        }
                    }
                });
                okButton.setActionCommand("OK");
                buttonPane.add(okButton);
                getRootPane().setDefaultButton(okButton);
            }
            {
                JButton cancelButton = new JButton("취소");
                cancelButton.addMouseListener(new MouseAdapter() {
                    @Override
                    public void mouseClicked(MouseEvent e) {
                        dispose();
                    }
                });
                cancelButton.setActionCommand("Cancel");
                buttonPane.add(cancelButton);
            }
        }
    }
}


import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTextField;
import javax.swing.JTable;
import javax.swing.JScrollPane;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.IOException;

public class Address extends JDialog {

    private final JPanel contentPanel = new JPanel();
    private JTextField textField;
    private JTable table;
    public String[] zipcode;
    public String address="";
    
    public Address() {
        setTitle("Address");
        setModal(true);         //이 창을 닫기전까지 부모창으로 갈 수 없음
        setResizable(false);    //사이즈 변경불가능
        setBounds(100, 100, 624, 365);
        getContentPane().setLayout(new BorderLayout());
        contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
        getContentPane().add(contentPanel, BorderLayout.CENTER);
        contentPanel.setLayout(null);
        {
            textField = new JTextField();
            textField.setBounds(12, 24, 475, 21);
            contentPanel.add(textField);
            textField.setColumns(10);
        }
        {
            JButton btnNewButton = new JButton("동이름 검색");
            btnNewButton.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent arg0) {
                    //검색 동이름 읽음 
                    String strDong = textField.getText();
                     try {
                             //주소 검색후 결과를 table model에 넣음
                             table.setModel(new AddressSearch(strDong));
                             //table 행의 넓이를 조절
                             table.getColumnModel().getColumn(4).setPreferredWidth(180);
                     } catch (IOException e1) {
                             e1.printStackTrace();
                     }
                }
            });
            btnNewButton.setBounds(499, 23, 97, 23);
            contentPanel.add(btnNewButton);
        }
        {
            JScrollPane scrollPane = new JScrollPane();
            scrollPane.setBounds(12, 55, 584, 229);
            contentPanel.add(scrollPane);
            {
                table = new JTable();
                scrollPane.setViewportView(table);
                
            }
        }
        {
            JPanel buttonPane = new JPanel();
            buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
            getContentPane().add(buttonPane, BorderLayout.SOUTH);
            {
                JButton okButton = new JButton("OK");
                okButton.addMouseListener(new MouseAdapter() {
                    @Override
                    public void mouseClicked(MouseEvent e) {
                        if(table.getSelectedRow()!=-1){ //주소를 검색하지 않고 확인누르면 그냥 닫힘
                            //클릭한 행의 우편번호를 멤버변수에 저장
                            zipcode = table.getValueAt(table.getSelectedRow(), 0).toString().split("-");
                            for(int i=1;i<5;i++){
                                //클릭한 행의 주소를 멤버변수에 저장
                                address += table.getValueAt(table.getSelectedRow(), i)+" ";
                            }
                            setVisible(false);;
                        }else{
                            dispose();
                        }
                    }
                });
                okButton.setActionCommand("OK");
                buttonPane.add(okButton);
                getRootPane().setDefaultButton(okButton);
            }
            {
                JButton cancelButton = new JButton("Cancel");
                cancelButton.addMouseListener(new MouseAdapter() {
                    @Override
                    public void mouseClicked(MouseEvent e) {
                        dispose();
                    }
                });
                cancelButton.setActionCommand("Cancel");
                buttonPane.add(cancelButton);
            }
        }
    }

}


import java.io.IOException;
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 javax.swing.table.AbstractTableModel;

public class AddressSearch extends AbstractTableModel {
    //데이터
    ArrayList<String[]> datas2 = new ArrayList<String[]>();
    //컬럼명
    String[] columnNames = new String[] {
            "우편번호", "시도", "구군", "동", "번지"
        };
    
    public AddressSearch(String d) throws IOException  {
        // TODO Auto-generated constructor stub
        String url = "jdbc:oracle:thin:@127.0.0.1:1521:orcl";
        String user = "project_1";
        String password = "123456";

        Connection conn = null;
        PreparedStatement pstmt = null;
        ResultSet rs = null;

        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            System.out.println("데이터베이스 로딩 성공");

            conn = DriverManager.getConnection(url, user, password);
            System.out.println("데이터베이스 연결 성공");

            String sql = "select * from address where dong like ?";
            pstmt = conn.prepareStatement(sql);
            pstmt.setString(1, d+"%");

            rs = pstmt.executeQuery();
            while (rs.next()) {
                String zipcode = rs.getString("zipcode");
                String sido = rs.getString("sido");
                String gugun = rs.getString("gugun");
                String dong = rs.getString("dong");
                String ri = rs.getString("ri") != null?rs.getString("ri"):"";
                String bunji = rs.getString("bunji") != null?rs.getString("bunji"):"";
                
                String[] data = {zipcode, sido, gugun, dong, ri +" "+ bunji};
                datas2.add(data);
            }

            // sql 매개변수없이 실행됨
            pstmt.executeUpdate();
            System.out.println("SQL 실행 성공");

        } catch (ClassNotFoundException e) {
            System.out.println("[에러] : " + e.getMessage());
        } catch (SQLException e) {
            System.out.println("[에러] : " + e.getMessage());
        } 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) {}
        }
        
    }
    
    @Override
    public String getColumnName(int column) {
        // TODO Auto-generated method stub
        return columnNames[column];
    }
    
    @Override
    public int getColumnCount() {
        // TODO Auto-generated method stub
        return datas2.get(0).length;
    }

    @Override
    public int getRowCount() {
        // TODO Auto-generated method stub
        return datas2.size();
    }

    @Override
    public Object getValueAt(int arg0, int arg1) {
        // TODO Auto-generated method stub
        return datas2.get(arg0)[arg1];
    }

}


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class MemberSave {

    public MemberSave(String name, String sex, String phone, String email, String birthday, String solar, String zipcode, String address1, String address2, String company, String position, String etc) {
        String url = "jdbc:oracle:thin:@127.0.0.1:1521:orcl";
        String user = "project_1";
        String password = "123456";
          
        Connection conn = null;
        PreparedStatement pstmt = null;
    
        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            System.out.println("데이터베이스 로딩 성공");
            
            conn = DriverManager.getConnection(url, user, password);
            System.out.println("데이터베이스 연결 성공");
            
            String sql = "insert into member(name, sex, phone, email, birthday, solar, zipcode, address1, address2, company, position, etc) values(?,?,?,?,?,?,?,?,?,?,?,?)";
            pstmt = conn.prepareStatement(sql);
            pstmt.setString(1, name);
            pstmt.setString(2, sex);
            pstmt.setString(3, phone);
            pstmt.setString(4, email);
            pstmt.setString(5, birthday);
            pstmt.setString(6, solar);
            pstmt.setString(7, zipcode);
            pstmt.setString(8, address1);
            pstmt.setString(9, address2);
            pstmt.setString(10, company);
            pstmt.setString(11, position);
            pstmt.setString(12, etc);
            
            pstmt.executeUpdate();
            System.out.println("SQL 실행 성공");
        } catch (ClassNotFoundException e) {
           // TODO Auto-generated catch block
           System.out.println("[에러] : "+e.getMessage());
        } catch (SQLException e) {
           // TODO Auto-generated catch block
           System.out.println("[에러] : "+e.getMessage());
        } finally {
           if(pstmt != null) try { pstmt.close(); } catch(SQLException e){}
           if(conn != null) try { conn.close(); } catch(SQLException e){}
        }
    }

    public MemberSave(String prename, String prephone, String name, String sex, String phone, String email, String birthday, String solar, String zipcode, String address1, String address2, String company, String position, String etc) {
        String url = "jdbc:oracle:thin:@127.0.0.1:1521:orcl";
        String user = "project_1";
        String password = "123456";
          
        Connection conn = null;
        PreparedStatement pstmt = null;
        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            System.out.println("데이터베이스 로딩 성공");
            
            conn = DriverManager.getConnection(url, user, password);
            System.out.println("데이터베이스 연결 성공");
            
            //이름과 폰번호가 일치하는 데이터베이스 행을 수정함
                String sql_2 = "update member set name =?, sex=?, phone=?, email=?, birthday=?, solar=?, zipcode=?, address1=?, address2=?, company=?, position=?, etc=? where name=? and phone=?";
                pstmt = conn.prepareStatement(sql_2);
                pstmt.setString(1, name);
                pstmt.setString(2, sex);
                pstmt.setString(3, phone);
                pstmt.setString(4, email);
                pstmt.setString(5, birthday);
                pstmt.setString(6, solar);
                pstmt.setString(7, zipcode);
                pstmt.setString(8, address1);
                pstmt.setString(9, address2);
                pstmt.setString(10, company);
                pstmt.setString(11, position);
                pstmt.setString(12, etc);
                pstmt.setString(13, prename);
                pstmt.setString(14, prephone);
                pstmt.executeUpdate();
            
            System.out.println("SQL 실행 성공");
        } catch (ClassNotFoundException e) {
           // TODO Auto-generated catch block
           System.out.println("[에러] : "+e.getMessage());
        } catch (SQLException e) {
           // TODO Auto-generated catch block
           System.out.println("[에러] : "+e.getMessage());
        } finally {
           if(pstmt != null) try { pstmt.close(); } catch(SQLException e){}
           if(conn != null) try { conn.close(); } catch(SQLException e){}
        }
    }
}


7.membership
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.io.IOException;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JLabel;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class Membership extends JDialog {

    private final JPanel contentPanel = new JPanel();
    private JTable table;
    private JTextField textField;



    /**
     * Create the dialog.
     */
    public Membership() throws IndexOutOfBoundsException{
        setTitle("Membership");
        setModal(true);         //이 창을 닫기전까지 부모창으로 갈 수 없음
        setResizable(false);    //사이즈 변경불가능
        setBounds(100, 100, 650, 386);
        getContentPane().setLayout(new BorderLayout());
        contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
        getContentPane().add(contentPanel, BorderLayout.CENTER);
        contentPanel.setLayout(null);
        
        JScrollPane scrollPane = new JScrollPane();
        scrollPane.setBounds(12, 46, 610, 259);
        contentPanel.add(scrollPane);
        
        table = new JTable();
        scrollPane.setViewportView(table);
        try {
            table.setModel(new MembershipSearch());
        } catch (IOException e) {
            e.printStackTrace();
        }
        table.getColumnModel().getColumn(0).setPreferredWidth(70);
        table.getColumnModel().getColumn(2).setPreferredWidth(40);
        table.getColumnModel().getColumn(3).setPreferredWidth(70);
        table.getColumnModel().getColumn(4).setPreferredWidth(30);
        table.getColumnModel().getColumn(5).setPreferredWidth(30);
        table.getColumnModel().getColumn(6).setPreferredWidth(30);
        table.getColumnModel().getColumn(7).setPreferredWidth(30);
        //값이 바뀔때마다 금액을 옆에 표시함
        table.addPropertyChangeListener(new PropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent evt) {
                //선택한 행이 있을경우, 첫번째 열을 클릭 했을 경우
                if(table.getSelectedRow()!=-1 & table.getSelectedColumn()==0) { 
                    //납입확인을 클릭했을 경우 → 텍스트필드 금액을 테이블에 체워넣음
                    if(((Boolean)table.getValueAt(table.getSelectedRow(),0)).booleanValue()==true){
                        table.setValueAt(textField.getText(), table.getSelectedRow(), 1);
                    }else{
                        table.setValueAt("0", table.getSelectedRow(), 1);
                    }
                }
            }
        });
        
        textField = new JTextField();
        textField.setBounds(86, 13, 167, 21);
        contentPanel.add(textField);
        textField.setColumns(10);
        
        JLabel lblNewLabel = new JLabel("회비 금액");
        lblNewLabel.setBounds(10, 16, 63, 15);
        contentPanel.add(lblNewLabel);
        {
            JPanel buttonPane = new JPanel();
            buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
            getContentPane().add(buttonPane, BorderLayout.SOUTH);
            {
                JButton okButton = new JButton("적 용");
                okButton.addMouseListener(new MouseAdapter() {
                    @Override
                    public void mouseClicked(MouseEvent e) {
                        //회비,이름,전화번호를 받아옴
                        String[] fee = new String[table.getRowCount()];
                        String[] name = new String[table.getRowCount()];
                        String[] phone = new String[table.getRowCount()];
                        int sumfee = 0;
                        
                        for(int i=0;i<=table.getRowCount()-1;i++){
                            fee[i]=(String)table.getValueAt(i, 1);
                            name[i]=(String)table.getValueAt(i, 2);
                            phone[i]=(String)table.getValueAt(i, 3);
                            sumfee += Integer.parseInt(fee[i]);
                        }
                        //회비를 데이터베이스에 저장
                        MembershipSave ms = new MembershipSave(fee,name,phone);
                        new AccountSave(""+sumfee, ms.colname.substring(1)+"회 회비금액 합계");
                        //화면을 다시 로딩
                        try {
                            table.setModel(new MembershipSearch());
                        } catch (IOException e1) {
                            e1.printStackTrace();
                        }
                    }
                });
                okButton.setActionCommand("OK");
                buttonPane.add(okButton);
                getRootPane().setDefaultButton(okButton);
            }
            {
                JButton cancelButton = new JButton("닫 기");
                cancelButton.addMouseListener(new MouseAdapter() {
                    @Override
                    public void mouseClicked(MouseEvent e) {
                        dispose();
                    }
                });
                cancelButton.setActionCommand("Cancel");
                buttonPane.add(cancelButton);
            }
        }
    }
}


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;

public class MembershipSave {
    String url = "jdbc:oracle:thin:@127.0.0.1:1521:orcl";
    String user = "project_1";
    String password = "123456";
    String colname;
    
    public MembershipSave(String[] fee, String[] name, String[] phone) {
        Connection conn = null;
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        
        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            System.out.println("데이터베이스 로딩 성공");
            
            conn = DriverManager.getConnection(url, user, password);
            System.out.println("데이터베이스 연결 성공");
            
            String sql = "select * from member";
            pstmt = conn.prepareStatement(sql);

            rs = pstmt.executeQuery();
            int num = rs.getMetaData().getColumnCount();
            ResultSetMetaData rsmd = rs.getMetaData();
            colname = rsmd.getColumnName(num);
            //마지막 컬럼이름이 n+숫자인지 검사
            if(colname.equals("ETC")){
                colname="n1";
            }else{
                colname="n"+(Integer.parseInt(colname.substring(1))+1);
            }
            
            String sql_1 = "alter table member add("+colname+" varchar2(30))";
            pstmt = conn.prepareStatement(sql_1);
            pstmt.executeUpdate();
            
            //이름과 폰번호가 일치하는 데이터베이스 행에 회비를 넣음
            for(int i=0;i<fee.length;i++){
                String sql_2 = "update member set "+colname+" =? where name=? and phone=?";
                pstmt = conn.prepareStatement(sql_2);
                pstmt.setString(1, fee[i]);
                pstmt.setString(2, name[i]);
                pstmt.setString(3, phone[i]);
                pstmt.executeUpdate();
            }
            
            System.out.println("SQL 실행 성공");
        } catch (ClassNotFoundException e) {
           // TODO Auto-generated catch block
           System.out.println("[에러] : "+e.getMessage());
        } catch (SQLException e) {
           // TODO Auto-generated catch block
           System.out.println("[에러] : "+e.getMessage());
        } finally {
           if(pstmt != null) try { pstmt.close(); } catch(SQLException e){}
           if(conn != null) try { conn.close(); } catch(SQLException e){}
           if(rs != null) try { rs.close(); } catch(SQLException e){}
        }
    }
}


import java.io.IOException;
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 javax.swing.table.AbstractTableModel;

public class MembershipSearch extends AbstractTableModel{
    //데이터
    ArrayList<Object[]> datas1 = new ArrayList<Object[]>(); //메인창 mangement에 띄울 것
    ArrayList<Object[]> datas2 = new ArrayList<Object[]>(); //membership에 띄울 것
    ArrayList<Object[]> datas3 = new ArrayList<Object[]>(); //수정창에 띄울 것
    //컬럼명
    String[] columnNames1 = new String[] { "-3회", "-2회", "-1회", "이름", "번호", "근무지", "직책", "이메일", "생일" };
    String[] columnNames = new String[] { "납입확인", "금액", "이름", "전화번호", "-1회", "-2회", "-3회", "-4회" };
    //클래스 타입
    Class[] columnTypes1 = new Class[] { 
            String.class, String.class, String.class, String.class, String.class, String.class, String.class, String.class, String.class
    };
    Class[] columnTypes = new Class[] {    
            Boolean.class, String.class, String.class, String.class, String.class, String.class, String.class, String.class
    };
    
    
    public Class getColumnClass(int columnIndex) {
            return columnTypes[columnIndex];
    }; 
    
    
    public MembershipSearch() throws IOException  {
        // TODO Auto-generated constructor stub
        String url = "jdbc:oracle:thin:@127.0.0.1:1521:orcl";
        String user = "project_1";
        String password = "123456";

        Connection conn = null;
        PreparedStatement pstmt = null;
        ResultSet rs = null;

        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            System.out.println("데이터베이스 로딩 성공");

            conn = DriverManager.getConnection(url, user, password);
            System.out.println("데이터베이스 연결 성공");

            String sql = "select * from member";
            pstmt = conn.prepareStatement(sql);

            rs = pstmt.executeQuery();
            int num = rs.getMetaData().getColumnCount();
            
            while (rs.next()) {
                String name = rs.getString("name");
                String sex = rs.getString("sex");
                String phone = rs.getString("phone");
                String email = rs.getString("email");
                String birthday = rs.getString("birthday");
                String solar = rs.getString("solar");
                String zipcode = rs.getString("zipcode");
                String address1 = rs.getString("address1");
                String address2 = rs.getString("address2");
                String company = rs.getString("company");
                String position = rs.getString("position");
                String etc = rs.getString("etc");
                int r1=0;
                int r2=0;
                int r3=0;
                int r4=0;
                //member 테이블의 가장 뒤의 컬럼부터 읽어들여 금액이 적혀있는 경우에 출력함, 숫자가 아니면 초기값 0
                try {r1 = Integer.parseInt(rs.getString(num));} catch (NumberFormatException e) {}
                String s1 =  ((Integer)r1).toString();
                try {r2 = Integer.parseInt(rs.getString(num-1));} catch (NumberFormatException e) {}
                String s2 =  ((Integer)r2).toString();
                try {r3 = Integer.parseInt(rs.getString(num-2));} catch (NumberFormatException e) {}
                String s3 =  ((Integer)r3).toString();
                try {r4 = Integer.parseInt(rs.getString(num-3));} catch (NumberFormatException e) {}
                String s4 =  ((Integer)r4).toString();
                                
                Object[] data1 = {r3==0?"x":"o", r2==0?"x":"o", r1==0?"x":"o", name, phone, company, position, email, birthday};
                Object[] data2 = {false, "0", name, phone, s1, s2, s3, s4};
                Object[] data3 = {name, sex, phone, email, birthday, solar, zipcode, address1, address2, company, position, etc};
                datas1.add(data1);
                datas2.add(data2);
                datas3.add(data3);
            }

            // sql 매개변수없이 실행됨
            pstmt.executeUpdate();
            System.out.println("SQL 실행 성공");

        } catch (ClassNotFoundException e) {
            System.out.println("[에러] : " + e.getMessage());
        } catch (SQLException e) {
            System.out.println("[에러] : " + e.getMessage());
        } 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) {}
        }
        
    }
    
    boolean[] columnEditables = new boolean[] {
            true, true, false, false, false, false, false, false
    };
    
    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex) {
        // TODO Auto-generated method stub
        return columnEditables[columnIndex];
    }


    @Override
    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
        // TODO Auto-generated method stub
        datas2.get(rowIndex)[columnIndex] = aValue;
        fireTableCellUpdated(rowIndex, columnIndex);
    }


    @Override
    public void fireTableCellUpdated(int arg0, int arg1) {
        // TODO Auto-generated method stub
        super.fireTableCellUpdated(arg0, arg1);
    }


    @Override
    public String getColumnName(int column) {
        // TODO Auto-generated method stub
        return columnNames[column];
    }
    
    @Override
    public int getColumnCount() throws IndexOutOfBoundsException{
        // TODO Auto-generated method stub
        return datas2.get(0).length;
    }

    @Override
    public int getRowCount() {
        // TODO Auto-generated method stub
        return datas2.size();
    }

    @Override
    public Object getValueAt(int arg0, int arg1) {
        // TODO Auto-generated method stub
        return datas2.get(arg0)[arg1];
    }
}


8
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.io.IOException;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.table.DefaultTableModel;
import javax.swing.JScrollPane;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeEvent;

public class Account extends JDialog {

    private final JPanel contentPanel = new JPanel();
    private JTable table;
    private JTextField textField;
    private JTextField textField_1;
    private JTextField textField_2;
    int j=5;

    /**
     * Create the dialog.
     */
    public Account() throws IndexOutOfBoundsException{
        setTitle("Account");
        setModal(true);         //이 창을 닫기전까지 부모창으로 갈 수 없음
        setResizable(false);    //사이즈 변경불가능
        setBounds(100, 100, 535, 431);
        getContentPane().setLayout(new BorderLayout());
        contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
        getContentPane().add(contentPanel, BorderLayout.CENTER);
        contentPanel.setLayout(null);

        JScrollPane scrollPane = new JScrollPane();
        scrollPane.setBounds(12, 78, 495, 241);
        contentPanel.add(scrollPane);
        {
            textField_1 = new JTextField();
            textField_1.setColumns(10);
            textField_1.setBounds(81, 41, 255, 21);
            contentPanel.add(textField_1);
        }
        {
            textField_2 = new JTextField();
            textField_2.setColumns(10);
            textField_2.setBounds(81, 329, 426, 21);
            contentPanel.add(textField_2);
        }
        
        table = new JTable();
        scrollPane.setViewportView(table);
        try {
            table.setModel(new AccountSearch());
            int sum=0;
            for(int i=0;i<table.getRowCount();i++){
                try {sum += Integer.parseInt((String)table.getValueAt(i, 0));} catch (NumberFormatException e) {}
                try {sum -= Integer.parseInt((String)table.getValueAt(i, 1));} catch (NumberFormatException e) {}
            }
            textField_2.setText(""+sum);
        } catch (IOException e) {
            e.printStackTrace();
        }
        table.getColumnModel().getColumn(2).setMinWidth(70);
        

        {
            textField = new JTextField();
            textField.setBounds(81, 10, 426, 21);
            contentPanel.add(textField);
            textField.setColumns(10);
        }
        {
            JLabel label = new JLabel("내 용");
            label.setBounds(12, 13, 57, 15);
            contentPanel.add(label);
        }
        {
            JLabel label = new JLabel("금 액");
            label.setBounds(12, 44, 57, 15);
            contentPanel.add(label);
        }
        
        {
            JButton btnNewButton = new JButton("수 익");
            btnNewButton.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent arg0) {
                    if(!textField.getText().equals("") & !textField_1.getText().equals("")){
                        table.setValueAt(textField.getText(), table.getRowCount()-j, 2);
                        table.setValueAt(textField_1.getText(), table.getRowCount()-j, 0);
                        j--;
                    }else{
                        System.out.println("값을 입력해야 합니다");
                    }
                    int sum=0;
                    for(int i=0;i<table.getRowCount();i++){
                        try {sum += Integer.parseInt((String)table.getValueAt(i, 0));} catch (NumberFormatException e) {}
                        try {sum -= Integer.parseInt((String)table.getValueAt(i, 1));} catch (NumberFormatException e) {}
                    }
                    textField_2.setText(""+sum);
                }
            });
            btnNewButton.setBounds(359, 41, 68, 23);
            contentPanel.add(btnNewButton);
        }
        {
            JButton button = new JButton("지 출");
            button.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    if(!textField.getText().equals("") & !textField_1.getText().equals("")){
                        table.setValueAt(textField.getText(), table.getRowCount()-j, 2);
                        table.setValueAt(textField_1.getText(), table.getRowCount()-j, 1);
                        j--;
                    }else{
                        System.out.println("값을 입력해야 합니다");
                    }
                    int sum=0;
                    for(int i=0;i<table.getRowCount();i++){
                        try {sum += Integer.parseInt((String)table.getValueAt(i, 0));} catch (NumberFormatException e1) {}
                        try {sum -= Integer.parseInt((String)table.getValueAt(i, 1));} catch (NumberFormatException e1) {}
                    }
                    textField_2.setText(""+sum);
                }
            });
            button.setBounds(439, 41, 68, 23);
            contentPanel.add(button);
        }
        {
            JLabel label = new JLabel("잔 액");
            label.setBounds(12, 332, 57, 15);
            contentPanel.add(label);
        }
        {
            JPanel buttonPane = new JPanel();
            buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
            getContentPane().add(buttonPane, BorderLayout.SOUTH);
            {
                JButton okButton = new JButton("적 용");
                okButton.addMouseListener(new MouseAdapter() {
                    @Override
                    public void mouseClicked(MouseEvent e) {
                        for(int i=table.getRowCount()-5;i<table.getRowCount()-j;i++){
                            String earn = (String)table.getValueAt(i, 0);
                            String spend = (String)table.getValueAt(i, 1);
                            String memo = (String)table.getValueAt(i, 2);
                            new AccountSave(earn, spend, memo);
                        }
                        dispose();
                    }
                });
                okButton.setActionCommand("OK");
                buttonPane.add(okButton);
                getRootPane().setDefaultButton(okButton);
            }
            {
                JButton cancelButton = new JButton("취 소");
                cancelButton.addMouseListener(new MouseAdapter() {
                    @Override
                    public void mouseClicked(MouseEvent e) {
                        dispose();
                    }
                });
                cancelButton.setActionCommand("Cancel");
                buttonPane.add(cancelButton);
            }
        }
    }

}


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class AccountSave {
    String url = "jdbc:oracle:thin:@127.0.0.1:1521:orcl";
    String user = "project_1";
    String password = "123456";
      
    public AccountSave(String earn,String memo) {
        Connection conn = null;
        PreparedStatement pstmt = null;
        
        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            System.out.println("데이터베이스 로딩 성공");
            
            conn = DriverManager.getConnection(url, user, password);
            System.out.println("데이터베이스 연결 성공");
            
            String sql = "insert into account(earn, spend, memo) values(?,?,?)";
            pstmt = conn.prepareStatement(sql);
            pstmt.setString(1, earn);
            pstmt.setString(2, "");
            pstmt.setString(3, memo);

            
            pstmt.executeUpdate();
            System.out.println("SQL 실행 성공");
        } catch (ClassNotFoundException e) {
           // TODO Auto-generated catch block
           System.out.println("[에러] : "+e.getMessage());
        } catch (SQLException e) {
           // TODO Auto-generated catch block
           System.out.println("[에러] : "+e.getMessage());
        } finally {
           if(pstmt != null) try { pstmt.close(); } catch(SQLException e){}
           if(conn != null) try { conn.close(); } catch(SQLException e){}
        }
    }
    
    public AccountSave(String earn, String spend, String memo) {
        Connection conn = null;
        PreparedStatement pstmt = null;
        
        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            System.out.println("데이터베이스 로딩 성공");
            
            conn = DriverManager.getConnection(url, user, password);
            System.out.println("데이터베이스 연결 성공");
            
            String sql = "insert into account(earn, spend, memo) values(?,?,?)";
            pstmt = conn.prepareStatement(sql);
            pstmt.setString(1, earn);
            pstmt.setString(2, spend);
            pstmt.setString(3, memo);

            
            pstmt.executeUpdate();
            System.out.println("SQL 실행 성공");
        } catch (ClassNotFoundException e) {
           // TODO Auto-generated catch block
           System.out.println("[에러] : "+e.getMessage());
        } catch (SQLException e) {
           // TODO Auto-generated catch block
           System.out.println("[에러] : "+e.getMessage());
        } finally {
           if(pstmt != null) try { pstmt.close(); } catch(SQLException e){}
           if(conn != null) try { conn.close(); } catch(SQLException e){}
        }
    }
    
    
}

import java.io.IOException;
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 javax.swing.table.AbstractTableModel;

public class AccountSearch extends AbstractTableModel{

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        
    }
    
    
    //데이터
    ArrayList<Object[]> datas2 = new ArrayList<Object[]>();
    //컬럼명
    String[] columnNames = new String[] { "수익", "지출", "내용" };
    //클래스 타입
    Class[] columnTypes = new Class[] { String.class, String.class, String.class }; 
    
    public AccountSearch() throws IOException  {
        // TODO Auto-generated constructor stub
        String url = "jdbc:oracle:thin:@127.0.0.1:1521:orcl";
        String user = "project_1";
        String password = "123456";

        Connection conn = null;
        PreparedStatement pstmt = null;
        ResultSet rs = null;

        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            System.out.println("데이터베이스 로딩 성공");

            conn = DriverManager.getConnection(url, user, password);
            System.out.println("데이터베이스 연결 성공");
            
            //멤버 테이블 읽음
            String sql = "select earn, spend, memo from account order by day";
            pstmt = conn.prepareStatement(sql);
            rs = pstmt.executeQuery();
            
            while (rs.next()) {
                    String s1 = rs.getString(1);
                    String s2 = rs.getString(2);
                    String s3 = rs.getString(3);
                
                    Object[] data = {s1, s2, s3};
                    datas2.add(data);
            }
            for(int i=0;i<5;i++){
                Object[] data = {null, null, null};
                datas2.add(data);
            }
            
            // sql 매개변수없이 실행됨
            pstmt.executeUpdate();
            System.out.println("SQL 실행 성공");

        } catch (ClassNotFoundException e) {
            System.out.println("[에러] : " + e.getMessage());
        } catch (SQLException e) {
            System.out.println("[에러] : " + e.getMessage());
        } 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) {}
        }
        
    }
    

    @Override
    public Class<?> getColumnClass(int columnIndex) {
        // TODO Auto-generated method stub
        return columnTypes[columnIndex];
    }


    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex) {
        // TODO Auto-generated method stub
        return false;
    }


    @Override
    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
        // TODO Auto-generated method stub
        datas2.get(rowIndex)[columnIndex] = aValue;
        fireTableCellUpdated(rowIndex, columnIndex);
    }


    @Override
    public void fireTableCellUpdated(int arg0, int arg1) {
        // TODO Auto-generated method stub
        super.fireTableCellUpdated(arg0, arg1);
    }


    @Override
    public String getColumnName(int column) {
        // TODO Auto-generated method stub
        return columnNames[column];
    }
    
    @Override
    public int getColumnCount() throws IndexOutOfBoundsException{
        // TODO Auto-generated method stub
        return datas2.get(0).length;
    }

    @Override
    public int getRowCount() {
        // TODO Auto-generated method stub
        return datas2.size();
    }

    @Override
    public Object getValueAt(int arg0, int arg1) {
        // TODO Auto-generated method stub
        return datas2.get(arg0)[arg1];
    }
}


9.email
import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JTextArea;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;

public class Email extends JDialog {

    private final JPanel contentPanel = new JPanel();
    private JTextField textField;
    private JTextField textField_1;
    private JTextField textField_2;
    private JTextArea textArea;

    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        try {
            Email dialog = new Email();
            dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
            dialog.setVisible(true);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * Create the dialog.
     */
    public Email() {
        setTitle("Email");
        setModal(true);         //이 창을 닫기전까지 부모창으로 갈 수 없음
        setResizable(false);    //사이즈 변경불가능
        setBounds(100, 100, 450, 334);
        getContentPane().setLayout(new BorderLayout());
        contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
        getContentPane().add(contentPanel, BorderLayout.CENTER);
        contentPanel.setLayout(null);
        
        JLabel lblNewLabel = new JLabel("받는 사람");
        lblNewLabel.setBounds(12, 10, 57, 15);
        contentPanel.add(lblNewLabel);
        
        textField = new JTextField();
        textField.setText("모두에게");
        textField.setBounds(75, 7, 347, 21);
        contentPanel.add(textField);
        textField.setColumns(10);
        
        JLabel label = new JLabel("제 목");
        label.setBounds(12, 38, 57, 15);
        contentPanel.add(label);
        
        textField_1 = new JTextField();
        textField_1.setColumns(10);
        textField_1.setBounds(75, 35, 347, 21);
        contentPanel.add(textField_1);
        
        JLabel label_1 = new JLabel("내 용");
        label_1.setBounds(12, 68, 57, 15);
        contentPanel.add(label_1);
        
        textArea = new JTextArea();
        textArea.setBounds(12, 88, 410, 131);
        contentPanel.add(textArea);
        
        JLabel label_2 = new JLabel("첨부 파일");
        label_2.setBounds(12, 232, 57, 15);
        contentPanel.add(label_2);
        
        textField_2 = new JTextField();
        textField_2.setColumns(10);
        textField_2.setBounds(75, 229, 247, 21);
        contentPanel.add(textField_2);
        
        JButton btnNewButton = new JButton("파일 찾기");
        btnNewButton.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                //첨부 파일선택기
                JFileChooser fileChooser = new JFileChooser("c:\\");
                int result = fileChooser.showOpenDialog(Email.this);
                if(result == JFileChooser.APPROVE_OPTION){
                    //파일경로를 텍스트 필드에 전달
                    textField_2.setText(fileChooser.getSelectedFile().getAbsolutePath());
                }else{
                    System.out.println("파일선택 안함");
                }
            }
        });
        btnNewButton.setBounds(325, 228, 97, 23);
        contentPanel.add(btnNewButton);
        
        JButton btnNewButton_1 = new JButton("불러오기");
        btnNewButton_1.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                //데이터베이스에서 형식 불러오기
                EmailSave es = new EmailSave();
                textArea.setText(es.eformat);
            }
        });
        btnNewButton_1.setBounds(325, 66, 97, 23);
        contentPanel.add(btnNewButton_1);
        
        JButton button = new JButton("형식 저장");
        button.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                //데이터베이스에 이메일 형식 저장
                String eformat = textArea.getText();
                new EmailSave(eformat);
            }
        });
        button.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
            }
        });
        button.setBounds(225, 66, 97, 23);
        contentPanel.add(button);
        {
            JPanel buttonPane = new JPanel();
            buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
            getContentPane().add(buttonPane, BorderLayout.SOUTH);
            {
                JButton okButton = new JButton("보내기");
                okButton.addMouseListener(new MouseAdapter() {
                    @Override
                    public void mouseClicked(MouseEvent e) {
                        EmailPassword ep = new EmailPassword();
                        ep.setVisible(true);
                        String sendemail=ep.textField.getText();
                        String sendpassword=ep.passwordField.getText();
                        //보낼주소 데이터베이스에서 받기
                        ArrayList<String> toEmail = new EmailGetAll().email;
                        //제목 받기
                        String subject = textField_1.getText();
                        
                        //내용받기
                        String content = textArea.getText();
                        //첨부파일주소 받기
                        String addFile = textField_2.getText();
                        //메일보내기
                        EmailSender mail = new EmailSender(sendemail, sendpassword);
                        for(int i=0;i<toEmail.size();i++){
                            if(!toEmail.get(i).equals("")){ //메일주소값이 있어야지 메일 보냄
                                mail.sendMail(toEmail.get(i), "모임회원", subject, content, addFile);
                            }
                        }
                        dispose(); //보낸 뒤에 창 닫기
                    }
                });
                okButton.setActionCommand("OK");
                buttonPane.add(okButton);
                getRootPane().setDefaultButton(okButton);
            }
            {
                JButton cancelButton = new JButton("취 소");
                cancelButton.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        dispose();
                    }
                });
                cancelButton.setActionCommand("Cancel");
                buttonPane.add(cancelButton);
            }
        }
    }
}


//인증클래스 생성
import javax.mail.Authenticator;
import javax.mail.PasswordAuthentication;

public class EmailAuth extends Authenticator {
    private String fromEmail;
    private String password;
    
    //생성자
    public EmailAuth(String fromEmail, String password) {
        this.fromEmail = fromEmail;
        this.password = password;
    }
    
    @Override
    protected PasswordAuthentication getPasswordAuthentication() {
        // TODO Auto-generated method stub
        return new PasswordAuthentication(fromEmail, password);
    }
    
}


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

public class EmailGetAll {
    String url = "jdbc:oracle:thin:@127.0.0.1:1521:orcl";
    String user = "project_1";
    String password = "123456";
    //모든 이메일 주소 받을 리스트 만듦
    ArrayList<String> email= new ArrayList<>(50);
    
    public EmailGetAll() {
        Connection conn = null;
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        
        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            System.out.println("데이터베이스 로딩 성공");
            
            conn = DriverManager.getConnection(url, user, password);
            System.out.println("데이터베이스 연결 성공");
            
            //이메일주소 모두 가져오기
            String sql = "select email from member";
            pstmt = conn.prepareStatement(sql);
            
            rs = pstmt.executeQuery();
               while(rs.next()){
                email.add(rs.getString("email")); 
               }
               
           //sql 매개변수없이 실행됨
           pstmt.executeUpdate();
           System.out.println("SQL 실행 성공");
        } catch (ClassNotFoundException e) {
           // TODO Auto-generated catch block
           System.out.println("[에러] : "+e.getMessage());
        } catch (SQLException e) {
           // TODO Auto-generated catch block
           System.out.println("[에러] : "+e.getMessage());
        } finally {
           if(pstmt != null) try { pstmt.close(); } catch(SQLException e){}
           if(conn != null) try { conn.close(); } catch(SQLException e){}
        }
    }
}


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class EmailSave {
    String url = "jdbc:oracle:thin:@127.0.0.1:1521:orcl";
    String user = "project_1";
    String password = "123456";
    //이메일 형식 저장할 멤버변수
    String eformat ="";
    
    public EmailSave() {
        Connection conn = null;
        PreparedStatement pstmt = null;
        ResultSet rs = null;

        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            System.out.println("데이터베이스 로딩 성공");
            
            conn = DriverManager.getConnection(url, user, password);
            System.out.println("데이터베이스 연결 성공");
            
            //이메일 형식 가져오기
            String sql = "select eformat from email";
            pstmt = conn.prepareStatement(sql);
            
            rs = pstmt.executeQuery();
               while(rs.next()){
                eformat = rs.getString("eformat"); 
               }
               
               //sql 매개변수없이 실행됨
               pstmt.executeUpdate();
               System.out.println("SQL 실행 성공");
        } catch (ClassNotFoundException e) {
           // TODO Auto-generated catch block
           System.out.println("[에러] : "+e.getMessage());
        } catch (SQLException e) {
           // TODO Auto-generated catch block
           System.out.println("[에러] : "+e.getMessage());
        } finally {
           if(pstmt != null) try { pstmt.close(); } catch(SQLException e){}
           if(conn != null) try { conn.close(); } catch(SQLException e){}
        }
    }
    
    
    
    
    public EmailSave(String eformat) {
        Connection conn = null;
        PreparedStatement pstmt = null;
    
        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            System.out.println("데이터베이스 로딩 성공");
            
            conn = DriverManager.getConnection(url, user, password);
            System.out.println("데이터베이스 연결 성공");
            
            //이메일 형식 업데이트 하기
            String sql = "update email set eformat =?";
            pstmt = conn.prepareStatement(sql);
            pstmt.setString(1, eformat);
            
            pstmt.executeUpdate();
            System.out.println("SQL 실행 성공");
        } catch (ClassNotFoundException e) {
           // TODO Auto-generated catch block
           System.out.println("[에러] : "+e.getMessage());
        } catch (SQLException e) {
           // TODO Auto-generated catch block
           System.out.println("[에러] : "+e.getMessage());
        } finally {
           if(pstmt != null) try { pstmt.close(); } catch(SQLException e){}
           if(conn != null) try { conn.close(); } catch(SQLException e){}
        }
    }
}


import java.io.File;
import java.io.UnsupportedEncodingException;
import java.util.Properties;

import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;

public class EmailSender {
    private String fromEmail = "보내는메일";
    private String password = "비밀번호";
    
    public EmailSender(String sendemail, String sendpassword) {
        // TODO Auto-generated constructor stub
        fromEmail = sendemail;
        password = sendpassword;
    }
    
    public void sendMail(String toEmail, String fromName, String subject, String content, String addFile){
        try {
            Properties props = new Properties();
            props.put("mail.smtp.starttls.enable", "true");  
            props.put("mail.transport.protocol", "stmp"); 
            props.put("mail.smtp.host", "smtp.gmail.com"); 
            props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
            props.put("mail.smtp.port", "465"); 
            props.put("mail.smtp.auth", "true");
            
            EmailAuth auth = new EmailAuth(fromEmail,password);
            Session sess = Session.getDefaultInstance(props,auth);
            
            // 메시지 
            MimeMessage msg = new MimeMessage(sess);
            msg.setHeader("content-type", "text/plain; charset=utf-8");
            msg.addRecipient(Message.RecipientType.TO, new InternetAddress(toEmail,fromName,"utf-8")); 
            msg.setSubject(subject);
            msg.setSentDate(new java.util.Date());
            
            // 내용
            Multipart multipart = new MimeMultipart();
            MimeBodyPart bodyPart = new MimeBodyPart();
            bodyPart.setContent(content,"text/plain; charset=utf-8");
            multipart.addBodyPart(bodyPart);
            //첨부파일
            if(!addFile.equals("")){ //첨부파일이 있을경우만 첨부파일 보내기
            bodyPart = new MimeBodyPart();
            FileDataSource fds = new FileDataSource(new File(addFile));
            bodyPart.setDataHandler(new DataHandler(fds));
            bodyPart.setFileName(fds.getName());
            multipart.addBodyPart(bodyPart);
            }
            msg.setContent(multipart);
            
            //전송
            Transport.send(msg);
            
            System.out.println("메일 전송이 완료되었습니다.");
        } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (MessagingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}


import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTextField;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JPasswordField;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class EmailPassword extends JDialog {

    private final JPanel contentPanel = new JPanel();
    public JTextField textField;
    public JPasswordField passwordField;

    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        try {
            EmailPassword dialog = new EmailPassword();
            dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
            dialog.setVisible(true);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * Create the dialog.
     */
    public EmailPassword() {
        setTitle("메일 입력창");
        setModal(true);         //이 창을 닫기전까지 부모창으로 갈 수 없음
        setResizable(false);    //사이즈 변경불가능
        setBounds(100, 100, 450, 202);
        getContentPane().setLayout(new BorderLayout());
        contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
        getContentPane().add(contentPanel, BorderLayout.CENTER);
        contentPanel.setLayout(null);
        
        textField = new JTextField();
        textField.setBounds(99, 39, 209, 21);
        contentPanel.add(textField);
        textField.setColumns(10);
        
        JLabel lblgooglecom = new JLabel("@google.com");
        lblgooglecom.setFont(new Font("굴림", Font.PLAIN, 15));
        lblgooglecom.setBounds(316, 39, 106, 21);
        contentPanel.add(lblgooglecom);
        
        JLabel lblNewLabel = new JLabel("보내는 메일");
        lblNewLabel.setBounds(12, 42, 87, 15);
        contentPanel.add(lblNewLabel);
        
        JLabel label = new JLabel("패스워드");
        label.setBounds(12, 79, 87, 15);
        contentPanel.add(label);
        
        passwordField = new JPasswordField();
        passwordField.setBounds(99, 76, 209, 18);
        contentPanel.add(passwordField);
        {
            JPanel buttonPane = new JPanel();
            buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
            getContentPane().add(buttonPane, BorderLayout.SOUTH);
            {
                JButton okButton = new JButton("OK");
                okButton.addMouseListener(new MouseAdapter() {
                    @Override
                    public void mouseClicked(MouseEvent e) {
                        setVisible(false);
                    }
                });
                okButton.setActionCommand("OK");
                buttonPane.add(okButton);
                getRootPane().setDefaultButton(okButton);
            }
            {
                JButton cancelButton = new JButton("Cancel");
                cancelButton.addMouseListener(new MouseAdapter() {
                    @Override
                    public void mouseClicked(MouseEvent e) {
                        dispose();
                    }
                });
                cancelButton.setActionCommand("Cancel");
                buttonPane.add(cancelButton);
            }
        }
    }
}


댓글 없음:

댓글 쓰기