Page 45 - 3-2
P. 45

stmt.close();
                                            }catch(SQLException se2){
                                            }
                                            try{
                                                            if(con!=null)
                                                                    con.close();
                                            }catch(SQLException se) {
                                                    se.printStackTrace();
                                            }
                            }
                            JButton btnNewButton = new JButton("\uACB0\uC81C");
                            //  결제버튼
                            contentPane.add(btnNewButton,"South");
                            btnNewButton.setFont(new Font("1  훈고딕굴림 R", Font.PLAIN, 15));
                            btnNewButton.addActionListener(new ActionListener() {
                                    public void actionPerformed(ActionEvent arg0) {
                                            MDP_Project2.this.setVisible(false);
                                            mdp_Project3.setVisible(true);
                                    }
                            });


                            JButton delete = new JButton(" 삭제"); // delete 버튼
                            contentPane.add(delete,"North");
                            delete.addActionListener(new ActionListener() {
                                    @Override
                                    public void actionPerformed(ActionEvent arg0) {
                                            if(table.getSelectedRow() == -1)
                                            {
                                                    return;
                                            }
                                            else
                                            {
                                    int row = table.getSelectedRow();
                                    Object value = table.getValueAt(row, 0);
                                    System.out.println(value);
                                    model.removeRow(table.getSelectedRow());
                            java.sql.Statement stmt = null;   //  데이터베이스 연결
                                    Connection con = null;
                                    int rs2 = 0;
                                    try {
                                            Class.forName("com.mysql.jdbc.Driver");
            con=DriverManager.getConnection("jdbc:mysql://localhost/mdp?useSSL=false", "root", "raspberry");


                    String sql = "DELETE FROM mdp_table1 where code = '"+value+"';";
                                                            stmt = con.createStatement();


                                                         - 45 -
   40   41   42   43   44   45   46   47   48   49   50