게시판 즐겨찾기
편집
드래그 앤 드롭으로
즐겨찾기 아이콘 위치 수정이 가능합니다.
자바 JDBC질문입니다.
게시물ID : programmer_3746짧은주소 복사하기
작성자 : 고추리알
추천 : 0
조회수 : 263회
댓글수 : 1개
등록시간 : 2014/06/04 13:35:22
옵션
  • 본인삭제금지
package mymember.main;

import java.awt.EventQueue;
import java.awt.event.*;
import java.sql.*;
import java.util.List;
import javax.swing.*;
import mymember.dao.*;
import mymember.tools.*;
import mymember.vo.*;

public class MyGUIMain extends MyMemberSkin {
MyMemberDAO dao = new MyMemberDAO();
JTextField[] jtfs = new JTextField[] { textFieldId, textFieldName,
textFieldPassword, textFieldRemark };

public MyGUIMain() {
MyDaoGuiTools.setTable(table, jtfs, "select * from mymember");
btnInsert.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
MyMemberVO vo = new MyMemberVO();
vo.setId(textFieldId.getText());
vo.setName(textFieldName.getText());
vo.setPassword(textFieldPassword.getText());
vo.setRemark(textFieldRemark.getText());
try {
boolean insertOk = dao.insert(vo);
if (insertOk) {
JOptionPane.showMessageDialog(MyGUIMain.this,
"잘입력했습니다.");
MyDaoGuiTools.setTable(table, jtfs,
"select * from mymember");
} else {
JOptionPane.showMessageDialog(MyGUIMain.this,
"입력되지 않았어요");
}
} catch (SQLException e) {
e.printStackTrace();
}
}
});

btnDelete.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String id = textFieldId.getText();
try {
boolean deleteOk = dao.delete(id);
if (deleteOk) {
JOptionPane
.showMessageDialog(MyGUIMain.this, "잘지웠습니다.");
MyDaoGuiTools.setTable(table, jtfs,
"select * from mymember");
} else {
JOptionPane.showMessageDialog(MyGUIMain.this, "못지웠어요");
}
} catch (SQLException e1) {
e1.printStackTrace();
}
}
});

btnUpdate.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent arg0) {
MyMemberVO vo = new MyMemberVO();
vo.setId(textFieldId.getText());
vo.setName(textFieldName.getText());
vo.setPassword(textFieldPassword.getText());
vo.setRemark(textFieldRemark.getText());
try {
boolean updateOk = dao.update(vo);
if (updateOk) {
JOptionPane.showMessageDialog(MyGUIMain.this,
"잘수정했습니다.");
MyDaoGuiTools.setTable(table, jtfs,
"select * from mymember");
} else {
JOptionPane.showMessageDialog(MyGUIMain.this,
"수정못했습니다.");
}
} catch (SQLException e) {
e.printStackTrace();
}
}

});

btnFind.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String id = textFieldId.getText();
if (id == null || id.equals("")) {
MyDaoGuiTools.setTable(table, jtfs,
"select * from mymember");
clear();
} else {
List<MyMemberVO> list = null;
try {
list = dao.select(id);
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}

MyMemberVO vo = null;
try {
vo = list.get(0);
} catch (Exception e1) {
JOptionPane.showMessageDialog(null, "자료를 못찾겠습니다.");
return;
}

textFieldName.setText(vo.getName());
textFieldPassword.setText(vo.getPassword());
textFieldRemark.setText(vo.getRemark());
MyDaoGuiTools.setTable(table, jtfs,
"select * from mymember where id='" + id + "'");
}
}
});

btnClear.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
clear();
}
});

}

private void clear() {
for (int i = 0; i < jtfs.length; i++) {
jtfs[i].setText(null);
}
}

public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
MyGUIMain frame = new MyGUIMain();
// MyDaoGuiTools.toMcUI(frame);
MyDaoGuiTools.toMcUI(frame);
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}

select 부분과 find 부분만 주석이 좀 필요합니다 
사용할려고보니 이해가 잘 안되서요...
죄송스럽지만 최대한 자세하게 주석 달아주세요 부탁드립니다 

전체 추천리스트 보기
새로운 댓글이 없습니다.
새로운 댓글 확인하기
글쓰기
◀뒤로가기
PC버전
맨위로▲
공지 운영 자료창고 청소년보호