일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
Tags
- 25가지 효율적인 sql작성법
- 상속
- 전체텍스트
- 다운캐스팅
- 자바
- 단축키
- 전자정부
- 업캐스팅
- 페이징
- 이클립스
- Validations
- 스프링
- while
- 전체
- 추상클래스
- Random
- 로또
- Login with OAuth Authentication
- IBatis procedure
- angular2
- 다형성
- 형변환
- 자바 야구게임
- 상속예제
- 가변인자
- Full text
- jquery
- full text indexing
- 야구게임
Archives
- Today
- Total
nalaolla
JDBC_간단게시판 본문
728x90
반응형
Creating a Table
오라클 스키마에 해당 테이블 등록
CREATE TABLE "JAVA_PROJECT"."BOARD"
( "NUM" NUMBER,
"TITLE" VARCHAR2(50 BYTE),
"CONTENT" VARCHAR2(2000 BYTE),
"WRITER" VARCHAR2(20 BYTE),
"REGDATE" DATE
);
Creating a Package
1. test.com.board.control
2. test.com.board.model
3. test.com.board.view
Package test.com.board.control
BoardDAO.java
- package test.com.board.control;
- import java.util.List;
- public interface BoardDAO {
- public int insert(BoardVO vo);
- public int update(BoardVO vo);
- public int delete(BoardVO vo);
- public BoardVO search(BoardVO vo);
- public List<BoardVO> select();
- public void search(String search, String searchString);
- }
BoardVO.java
- package test.com.board.control;
- import java.util.Date;
- public class BoardVO {
- int num;
- String title;
- String content;
- String name;
- Date regDate;
- public int getNum() {
- return num;
- }
- public void setNum(int num) {
- this.num = num;
- }
- public String getTitle() {
- return title;
- }
- public void setTitle(String title) {
- this.title = title;
- }
- public String getContent() {
- return content;
- }
- public void setContent(String content) {
- this.content = content;
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public Date getRegDate() {
- return regDate;
- }
- public void setRegDate(Date regDate) {
- this.regDate = regDate;
- }
- }
Package test.com.board.model
BoardDAOImpl.java
- package test.com.board.model;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.ArrayList;
- import java.util.List;
- import test.com.board.control.BoardDAO;
- import test.com.board.control.BoardVO;
- import test.com.board.view.BoardList2;
- public class BoardDAOImpl implements BoardDAO {
- Connection conn;
- PreparedStatement pstmt;
- ResultSet rs;
- public static final String DRIVER_NAME = "oracle.jdbc.OracleDriver";
- public static final String URL = "jdbc:oracle:thin:@localhost:1521:xe";
- public static final String USERID = "java_project";
- public static final String USERPWD = "hi123456";
- public BoardDAOImpl() {
- try {
- Class.forName(DRIVER_NAME);
- } catch (ClassNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- System.out.println("drive connect failed...");
- }
- }
- @Override
- public int insert(BoardVO vo) {
- try {
- conn = DriverManager.getConnection(URL, USERID, USERPWD);
- String sql = "insert into board(num, title, content, writer, regdate) values (SEQ_BOARD_NUM.NEXTVAL, ?, ?, ?, SYSDATE )";
- pstmt = conn.prepareStatement(sql);
- pstmt.setString(1, vo.getTitle());
- pstmt.setString(2, vo.getContent());
- pstmt.setString(3, vo.getName());
- pstmt.executeUpdate();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } finally {
- try {
- conn.close();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- return 0;
- }
- @Override
- public int update(BoardVO vo) {
- try {
- conn = DriverManager.getConnection(URL, USERID, USERPWD);
- String sql = "update board set title=?, content=?, writer=?, regdate=SYSDATE where num=?";
- pstmt = conn.prepareStatement(sql);
- pstmt.setString(1, vo.getTitle());
- pstmt.setString(2, vo.getContent());
- pstmt.setString(3, vo.getName());
- pstmt.setInt(4, vo.getNum());
- pstmt.executeUpdate();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } finally {
- try {
- conn.close();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- return 0;
- }
- @Override
- public int delete(BoardVO vo) {
- try {
- conn = DriverManager.getConnection(URL, USERID, USERPWD);
- String sql = "delete from board where num=?";
- pstmt = conn.prepareStatement(sql);
- pstmt.setInt(1, vo.getNum());
- pstmt.executeUpdate();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } finally {
- try {
- conn.close();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- return 0;
- }
- @Override
- public BoardVO search(BoardVO vo) {
- return null;
- }
- @Override
- public List<BoardVO> select() {
- List<BoardVO> list = new ArrayList<BoardVO>();
- try {
- conn = DriverManager.getConnection(URL, USERID, USERPWD);
- String sql = "select num, title, content, writer, regdate from board order by num desc";
- pstmt = conn.prepareStatement(sql);
- rs = pstmt.executeQuery();
- while (rs.next()) {
- BoardVO vo = new BoardVO();
- vo.setNum(rs.getInt("num"));
- vo.setTitle(rs.getString("title"));
- vo.setContent(rs.getString("content"));
- vo.setName(rs.getString("writer"));
- vo.setRegDate(rs.getDate("regdate"));
- list.add(vo);
- }
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } finally {
- try {
- rs.close();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- try {
- pstmt.close();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- try {
- conn.close();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- return list;
- }
- @Override
- public void search(String search, String searchString) {
- List<BoardVO> list = new ArrayList<BoardVO>();
- try {
- conn = DriverManager.getConnection(URL, USERID, USERPWD);
- String sql = "select num, title, content, writer, regdate from board where " + search + " like '%"
- + searchString + "%' order by num desc";
- pstmt = conn.prepareStatement(sql);
- rs = pstmt.executeQuery();
- while (rs.next()) {
- BoardVO vo = new BoardVO();
- vo.setNum(rs.getInt("num"));
- vo.setTitle(rs.getString("title"));
- vo.setContent(rs.getString("content"));
- vo.setName(rs.getString("writer"));
- vo.setRegDate(rs.getDate("regdate"));
- list.add(vo);
- }
- new BoardList2(list);
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } finally {
- try {
- rs.close();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- try {
- pstmt.close();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- try {
- conn.close();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
- }
Package test.com.board.view
BoardDAOImpl.java
- package test.com.board.model;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.ArrayList;
- import java.util.List;
- import test.com.board.control.BoardDAO;
- import test.com.board.control.BoardVO;
- import test.com.board.view.BoardList2;
- public class BoardDAOImpl implements BoardDAO {
- Connection conn;
- PreparedStatement pstmt;
- ResultSet rs;
- public static final String DRIVER_NAME = "oracle.jdbc.OracleDriver";
- public static final String URL = "jdbc:oracle:thin:@localhost:1521:xe";
- public static final String USERID = "java_project";
- public static final String USERPWD = "hi123456";
- public BoardDAOImpl() {
- try {
- Class.forName(DRIVER_NAME);
- } catch (ClassNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- System.out.println("drive connect failed...");
- }
- }
- @Override
- public int insert(BoardVO vo) {
- try {
- conn = DriverManager.getConnection(URL, USERID, USERPWD);
- String sql = "insert into board(num, title, content, writer, regdate) values (SEQ_BOARD_NUM.NEXTVAL, ?, ?, ?, SYSDATE )";
- pstmt = conn.prepareStatement(sql);
- pstmt.setString(1, vo.getTitle());
- pstmt.setString(2, vo.getContent());
- pstmt.setString(3, vo.getName());
- pstmt.executeUpdate();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } finally {
- try {
- conn.close();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- return 0;
- }
- @Override
- public int update(BoardVO vo) {
- try {
- conn = DriverManager.getConnection(URL, USERID, USERPWD);
- String sql = "update board set title=?, content=?, writer=?, regdate=SYSDATE where num=?";
- pstmt = conn.prepareStatement(sql);
- pstmt.setString(1, vo.getTitle());
- pstmt.setString(2, vo.getContent());
- pstmt.setString(3, vo.getName());
- pstmt.setInt(4, vo.getNum());
- pstmt.executeUpdate();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } finally {
- try {
- conn.close();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- return 0;
- }
- @Override
- public int delete(BoardVO vo) {
- try {
- conn = DriverManager.getConnection(URL, USERID, USERPWD);
- String sql = "delete from board where num=?";
- pstmt = conn.prepareStatement(sql);
- pstmt.setInt(1, vo.getNum());
- pstmt.executeUpdate();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } finally {
- try {
- conn.close();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- return 0;
- }
- @Override
- public BoardVO search(BoardVO vo) {
- return null;
- }
- @Override
- public List<BoardVO> select() {
- List<BoardVO> list = new ArrayList<BoardVO>();
- try {
- conn = DriverManager.getConnection(URL, USERID, USERPWD);
- String sql = "select num, title, content, writer, regdate from board order by num desc";
- pstmt = conn.prepareStatement(sql);
- rs = pstmt.executeQuery();
- while (rs.next()) {
- BoardVO vo = new BoardVO();
- vo.setNum(rs.getInt("num"));
- vo.setTitle(rs.getString("title"));
- vo.setContent(rs.getString("content"));
- vo.setName(rs.getString("writer"));
- vo.setRegDate(rs.getDate("regdate"));
- list.add(vo);
- }
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } finally {
- try {
- rs.close();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- try {
- pstmt.close();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- try {
- conn.close();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- return list;
- }
- @Override
- public void search(String search, String searchString) {
- List<BoardVO> list = new ArrayList<BoardVO>();
- try {
- conn = DriverManager.getConnection(URL, USERID, USERPWD);
- String sql = "select num, title, content, writer, regdate from board where " + search + " like '%"
- + searchString + "%' order by num desc";
- pstmt = conn.prepareStatement(sql);
- rs = pstmt.executeQuery();
- while (rs.next()) {
- BoardVO vo = new BoardVO();
- vo.setNum(rs.getInt("num"));
- vo.setTitle(rs.getString("title"));
- vo.setContent(rs.getString("content"));
- vo.setName(rs.getString("writer"));
- vo.setRegDate(rs.getDate("regdate"));
- list.add(vo);
- }
- new BoardList2(list);
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } finally {
- try {
- rs.close();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- try {
- pstmt.close();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- try {
- conn.close();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
- }
Package test.com.board.view
BoardInsert.java
- package test.com.board.view;
- import java.awt.Rectangle;
- import java.awt.Toolkit;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.ImageIcon;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JTextArea;
- import javax.swing.JTextField;
- import test.com.board.control.BoardDAO;
- import test.com.board.control.BoardVO;
- import test.com.board.model.BoardDAOImpl;
- public class BoardInsert extends JFrame {
- private JTextField title;
- private JTextField writer;
- public BoardInsert() {
- setBounds(new Rectangle(600, 0, 450, 280));
- setTitle("게시글등록");
- setIconImage(Toolkit.getDefaultToolkit().getImage(BoardInsert.class.getResource("/images/icon_editer.png")));
- getContentPane().setLayout(null);
- JLabel lblNewLabel = new JLabel("글제목");
- lblNewLabel.setBounds(12, 25, 57, 15);
- getContentPane().add(lblNewLabel);
- title = new JTextField("글제목입니다.");
- title.setBounds(81, 22, 340, 21);
- getContentPane().add(title);
- title.setColumns(10);
- JLabel lblNewLabel_1 = new JLabel("글내용");
- lblNewLabel_1.setBounds(12, 59, 57, 15);
- getContentPane().add(lblNewLabel_1);
- JTextArea textArea = new JTextArea("글내용 글내용..");
- textArea.setLineWrap(true);
- textArea.setRows(5);
- textArea.setBounds(81, 53, 340, 69);
- getContentPane().add(textArea);
- JLabel lblNewLabel_2 = new JLabel("작성자");
- lblNewLabel_2.setBounds(12, 140, 57, 15);
- getContentPane().add(lblNewLabel_2);
- writer = new JTextField("daniel,kim");
- writer.setBounds(81, 137, 116, 21);
- getContentPane().add(writer);
- writer.setColumns(10);
- JButton btnWrite = new JButton("작성완료");
- btnWrite.setIcon(new ImageIcon(BoardInsert.class.getResource("/images/icon_edit_01.png")));
- btnWrite.setBounds(81, 180, 116, 23);
- btnWrite.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- BoardDAO dao = new BoardDAOImpl();
- BoardVO vo = new BoardVO();
- String titles = title.getText();
- String txtarea = textArea.getText();
- String name = writer.getText();
- vo.setTitle(titles);
- vo.setContent(txtarea);
- vo.setName(name);
- dao.insert(vo);
- }
- });
- getContentPane().add(btnWrite);
- // JButton btnList = new JButton("리스트");
- // btnList.setIcon(new
- // ImageIcon(BoardInsert.class.getResource("/images/icon_docs_01.png")));
- // btnList.setBounds(190, 180, 97, 23);
- // btnList.addActionListener(new ActionListener() {
- //
- // @Override
- // public void actionPerformed(ActionEvent e) {
- // new BoardList();
- // }
- // });
- // getContentPane().add(btnList);
- JButton btnClose = new JButton("닫기");
- btnClose.setIcon(new ImageIcon(BoardInsert.class.getResource("/images/icon_stop_01.png")));
- btnClose.setBounds(209, 180, 97, 23);
- btnClose.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- setVisible(false);
- }
- });
- getContentPane().add(btnClose);
- setVisible(true);
- }
- }
BoardList.java
- package test.com.board.view;
- import java.awt.Color;
- import java.awt.Rectangle;
- import java.awt.Toolkit;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.MouseAdapter;
- import java.awt.event.MouseEvent;
- import java.util.List;
- import javax.swing.DefaultComboBoxModel;
- import javax.swing.ImageIcon;
- import javax.swing.JButton;
- import javax.swing.JComboBox;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JScrollPane;
- import javax.swing.JTable;
- import javax.swing.JTextField;
- import javax.swing.table.DefaultTableModel;
- import test.com.board.control.BoardDAO;
- import test.com.board.control.BoardVO;
- import test.com.board.model.BoardDAOImpl;
- public class BoardList extends JFrame {
- private JTable table;
- private JTextField searchString;
- public BoardList() {
- setTitle("Board List");
- setIconImage(Toolkit.getDefaultToolkit().getImage(BoardList.class.getResource("/images/icon_docs_01.png")));
- setBounds(new Rectangle(0, 0, 600, 350));
- getContentPane().setLayout(null);
- JScrollPane scrollPane = new JScrollPane();
- scrollPane.setBounds(12, 49, 560, 189);
- getContentPane().add(scrollPane);
- BoardDAO dao = new BoardDAOImpl();
- List<BoardVO> list = dao.select();
- String[] colNames = new String[] {"글번호", "제목", "내용...", "작성자", "작성일"};
- Object[][] rowDatas = new Object[list.size()][colNames.length];
- for (int i = 0; i < list.size(); i++) {
- rowDatas[i] = new Object[] {
- list.get(i).getNum(),
- list.get(i).getTitle(),
- list.get(i).getContent(),
- list.get(i).getName(),
- list.get(i).getRegDate()
- };
- }
- table = new JTable();
- table.setModel(new DefaultTableModel(rowDatas,colNames) {
- boolean[] columnEditables = new boolean[] {
- false, false, false, true, false
- };
- public boolean isCellEditable(int row, int column) {
- return columnEditables[column];
- }
- });
- table.getColumnModel().getColumn(0).setResizable(false);
- table.getColumnModel().getColumn(0).setPreferredWidth(45);
- table.getColumnModel().getColumn(1).setResizable(false);
- table.getColumnModel().getColumn(1).setPreferredWidth(200);
- table.getColumnModel().getColumn(2).setResizable(false);
- table.getColumnModel().getColumn(2).setPreferredWidth(164);
- table.getColumnModel().getColumn(4).setResizable(false);
- table.getColumnModel().getColumn(4).setPreferredWidth(140);
- table.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent e) {
- // TODO Auto-generated method stub
- int rowNum = table.getSelectedRow();
- BoardVO vos = new BoardVO();
- vos = list.get(rowNum);
- new BoardUpdate(vos);
- }
- });
- scrollPane.setViewportView(table);
- JLabel lblNewLabel = new JLabel("검색조건");
- lblNewLabel.setBounds(186, 20, 56, 15);
- getContentPane().add(lblNewLabel);
- JComboBox comboBox = new JComboBox();
- comboBox.setModel(new DefaultComboBoxModel(new String[] {"title", "content", "writer"}));
- comboBox.setBounds(244, 17, 74, 21);
- getContentPane().add(comboBox);
- searchString = new JTextField();
- searchString.setBounds(330, 17, 133, 21);
- getContentPane().add(searchString);
- searchString.setColumns(10);
- JButton btnSearch = new JButton("search..");
- btnSearch.setIcon(new ImageIcon(BoardList.class.getResource("/images/icon_search_01.png")));
- btnSearch.setBounds(466, 16, 106, 23);
- btnSearch.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- BoardDAO dao = new BoardDAOImpl();
- dao.search(String.valueOf(comboBox.getSelectedItem()), searchString.getText());
- setVisible(false);
- }
- });
- getContentPane().add(btnSearch);
- JLabel lblDesignByDanielkim = new JLabel("design by daniel,kim");
- lblDesignByDanielkim.setIcon(new ImageIcon(BoardList.class.getResource("/images/icon_title_01.png")));
- lblDesignByDanielkim.setForeground(Color.GRAY);
- lblDesignByDanielkim.setBounds(434, 286, 138, 15);
- getContentPane().add(lblDesignByDanielkim);
- JButton btnWrite = new JButton("글작성");
- btnWrite.setIcon(new ImageIcon(BoardList.class.getResource("/images/icon_edit_01.png")));
- btnWrite.setBounds(475, 248, 97, 23);
- btnWrite.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- new BoardInsert();
- }
- });
- getContentPane().add(btnWrite);
- setVisible(true);
- }
- }
BoardList2.java
- package test.com.board.view;
- import java.awt.Color;
- import java.awt.Rectangle;
- import java.awt.Toolkit;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.MouseAdapter;
- import java.awt.event.MouseEvent;
- import java.util.List;
- import javax.swing.DefaultComboBoxModel;
- import javax.swing.ImageIcon;
- import javax.swing.JButton;
- import javax.swing.JComboBox;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JScrollPane;
- import javax.swing.JTable;
- import javax.swing.JTextField;
- import javax.swing.table.DefaultTableModel;
- import test.com.board.control.BoardDAO;
- import test.com.board.control.BoardVO;
- import test.com.board.model.BoardDAOImpl;
- public class BoardList2 extends JFrame {
- private JTable table;
- private JTextField searchString;
- public BoardList2(List<BoardVO> vos) {
- setTitle("Board List");
- setIconImage(Toolkit.getDefaultToolkit().getImage(BoardList2.class.getResource("/images/icon_docs_01.png")));
- setBounds(new Rectangle(0, 0, 600, 350));
- getContentPane().setLayout(null);
- JScrollPane scrollPane = new JScrollPane();
- scrollPane.setBounds(12, 49, 560, 189);
- getContentPane().add(scrollPane);
- BoardDAO dao = new BoardDAOImpl();
- List<BoardVO> list = vos;
- String[] colNames = new String[] {"글번호", "제목", "내용...", "작성자", "작성일"};
- Object[][] rowDatas = new Object[list.size()][colNames.length];
- for (int i = 0; i < list.size(); i++) {
- rowDatas[i] = new Object[] {
- list.get(i).getNum(),
- list.get(i).getTitle(),
- list.get(i).getContent(),
- list.get(i).getName(),
- list.get(i).getRegDate()
- };
- }
- table = new JTable();
- table.setModel(new DefaultTableModel(rowDatas,colNames) {
- boolean[] columnEditables = new boolean[] {
- false, false, false, true, false
- };
- public boolean isCellEditable(int row, int column) {
- return columnEditables[column];
- }
- });
- table.getColumnModel().getColumn(0).setResizable(false);
- table.getColumnModel().getColumn(0).setPreferredWidth(45);
- table.getColumnModel().getColumn(1).setResizable(false);
- table.getColumnModel().getColumn(1).setPreferredWidth(200);
- table.getColumnModel().getColumn(2).setResizable(false);
- table.getColumnModel().getColumn(2).setPreferredWidth(164);
- table.getColumnModel().getColumn(4).setResizable(false);
- table.getColumnModel().getColumn(4).setPreferredWidth(140);
- table.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent e) {
- // TODO Auto-generated method stub
- int rowNum = table.getSelectedRow();
- BoardVO vos = new BoardVO();
- vos = list.get(rowNum);
- new BoardUpdate(vos);
- }
- });
- scrollPane.setViewportView(table);
- JLabel lblNewLabel = new JLabel("검색조건");
- lblNewLabel.setBounds(186, 20, 56, 15);
- getContentPane().add(lblNewLabel);
- JComboBox comboBox = new JComboBox();
- comboBox.setModel(new DefaultComboBoxModel(new String[] {"title", "content", "writer"}));
- comboBox.setBounds(244, 17, 74, 21);
- getContentPane().add(comboBox);
- searchString = new JTextField();
- searchString.setBounds(330, 17, 133, 21);
- getContentPane().add(searchString);
- searchString.setColumns(10);
- JButton btnSearch = new JButton("search..");
- btnSearch.setIcon(new ImageIcon(BoardList2.class.getResource("/images/icon_search_01.png")));
- btnSearch.setBounds(467, 16, 105, 23);
- btnSearch.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- BoardDAO dao = new BoardDAOImpl();
- dao.search(String.valueOf(comboBox.getSelectedItem()), searchString.getText());
- setVisible(false);
- }
- });
- getContentPane().add(btnSearch);
- JLabel lblDesignByDanielkim = new JLabel("design by daniel,kim");
- lblDesignByDanielkim.setIcon(new ImageIcon(BoardList2.class.getResource("/images/icon_title_01.png")));
- lblDesignByDanielkim.setForeground(Color.GRAY);
- lblDesignByDanielkim.setBounds(434, 286, 138, 15);
- getContentPane().add(lblDesignByDanielkim);
- JButton btnWrite = new JButton("글작성");
- btnWrite.setIcon(new ImageIcon(BoardList2.class.getResource("/images/icon_edit_01.png")));
- btnWrite.setBounds(475, 248, 97, 23);
- btnWrite.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- new BoardInsert();
- }
- });
- getContentPane().add(btnWrite);
- setVisible(true);
- }
- }
BoardUpdate.java
- package test.com.board.view;
- import java.awt.Rectangle;
- import java.awt.Toolkit;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.ImageIcon;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JTextArea;
- import javax.swing.JTextField;
- import test.com.board.control.BoardDAO;
- import test.com.board.control.BoardVO;
- import test.com.board.model.BoardDAOImpl;
- public class BoardUpdate extends JFrame {
- private JTextField title;
- private JTextField writer;
- public BoardUpdate(BoardVO vo) {
- final int num = vo.getNum();
- setBounds(new Rectangle(600, 0, 450, 280));
- setTitle("게시글 수정");
- setIconImage(Toolkit.getDefaultToolkit().getImage(BoardInsert.class.getResource("/images/icon_world_01.png")));
- getContentPane().setLayout(null);
- JLabel lblNewLabel = new JLabel("글제목");
- lblNewLabel.setBounds(12, 25, 57, 15);
- getContentPane().add(lblNewLabel);
- title = new JTextField(vo.getTitle());
- title.setBounds(81, 22, 340, 21);
- getContentPane().add(title);
- title.setColumns(10);
- JLabel lblNewLabel_1 = new JLabel("글내용");
- lblNewLabel_1.setBounds(12, 59, 57, 15);
- getContentPane().add(lblNewLabel_1);
- JTextArea textArea = new JTextArea(vo.getContent());
- textArea.setLineWrap(true);
- textArea.setRows(5);
- textArea.setBounds(81, 53, 340, 69);
- getContentPane().add(textArea);
- JLabel lblNewLabel_2 = new JLabel("작성자");
- lblNewLabel_2.setBounds(12, 140, 57, 15);
- getContentPane().add(lblNewLabel_2);
- writer = new JTextField(vo.getName());
- writer.setBounds(81, 137, 116, 21);
- getContentPane().add(writer);
- writer.setColumns(10);
- JButton btnWrite = new JButton("글수정");
- btnWrite.setIcon(new ImageIcon(BoardUpdate.class.getResource("/images/icon_repeat.png")));
- btnWrite.setBounds(81, 180, 97, 23);
- btnWrite.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- BoardDAO dao = new BoardDAOImpl();
- BoardVO vo = new BoardVO();
- String titles = title.getText();
- String txtarea = textArea.getText();
- String name = writer.getText();
- vo.setNum(num);
- vo.setTitle(title.getText());
- vo.setContent(textArea.getText());
- vo.setName(writer.getText());
- dao.update(vo);
- setVisible(false);
- }
- });
- getContentPane().add(btnWrite);
- JButton btnDel = new JButton("글삭제");
- btnDel.setIcon(new ImageIcon(BoardUpdate.class.getResource("/images/icon_garbage_01.gif")));
- btnDel.setBounds(190, 180, 97, 23);
- btnDel.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- BoardDAO dao = new BoardDAOImpl();
- BoardVO vo = new BoardVO();
- vo.setNum(num);
- dao.delete(vo);
- setVisible(false);
- }
- });
- getContentPane().add(btnDel);
- JButton btnClose = new JButton("닫기");
- btnClose.setIcon(new ImageIcon(BoardInsert.class.getResource("/images/icon_stop_01.png")));
- btnClose.setBounds(299, 180, 97, 23);
- btnClose.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- setVisible(false);
- }
- });
- getContentPane().add(btnClose);
- setVisible(true);
- }
- }
BoardMain.java
- package test.com.board.view;
- public class BoardMain {
- public static void main(String[] args) {
- new BoardList();
- }
- }
Project UML
Project Result Screen
1. 게시글 리스트 GUI
2. 게시글 등록 GUI
3. 게시글 수정 GUI
728x90
반응형
'JAVA > 26. JDBC' 카테고리의 다른 글
java 코드 오라클 저장 프로시저 호출 (0) | 2015.12.09 |
---|---|
프로시져 호출하여 리스트 출력 (0) | 2015.12.09 |