Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 명사 추출기
- docker
- 명사 뽑아내기
- 나의 취미
- 나의 프로젝트
- iBatis
- Eclipse
- node.js web framework
- Lift
- ajax
- Node.js
- nodejs express
- ejb
- C/C++
- Cross
- scala
- 책이야기
- 도커
- 디즈니씨
- express for node.js
- 명사 분석기
- rss
- flex3
- 베트남어
- 주식이야기
- 스킨 스쿠버
- 메일왕창보내는법
- php thumbnail
- ror실행
- php
Archives
- Today
- Total
nkdk의 세상
자바 Language 26일째 테이블에 마우스를 클릭하면 값 받아서 아 본문
package db;
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.table.*;
import javax.swing.*;
import pac.DBConnectionMgr;
public class JTableMon1 extends JFrame{
Object data[][]=new String[0][4];
Object data2[][]=new String[0][4];
DBConnectionMgr pool;
Connection conn;
Statement stmt;
ResultSet rs;
DefaultTableModel mod, mod2; // 테이블 데이타 모델을 클래스를 선언한다.
JTable tab, tab2;
String title[]={"부서번호", "부서명", "부서전화", "위치"};
String title2[]={"사번", "이름", "입사일", "성별"};
public JTableMon1() {
accDb();
display();
accSql();
tab.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent ea) {
// 객체 얻기
JTable tab=(JTable)ea.getComponent(); //<- 받아온 객체를 테이블에 받아옴
if(tab.getSelectedColumn()==1) {
accDsql();
}
}
});
}
public void accSql() {
try {
stmt=conn.createStatement();
// mod.setnumrow(0) -> 초기화
rs=stmt.executeQuery("select * from buser");
while(rs.next()) {
String b_no=rs.getString("buser_no");
String b_name=rs.getString("buser_name");
String b_tel=rs.getString("buser_tel");
String b_loc=rs.getString("buser_loc");
String imsi[]={b_no, b_name, b_tel, b_loc};
mod.addRow(imsi);
}
String im[]={"00","임시직","00-000-0000","기타"};
mod.addRow(im);
} catch (Exception ex) {
JOptionPane.showMessageDialog(this, "SQL오류1:"+ex);
}finally{
try{
rs.close(); stmt.close();
}catch (Exception e) {
JOptionPane.showMessageDialog(this, "SQL닫음오류:"+e);
}
}
}
public void accDsql() {
mod2.setRowCount(0);
try {
stmt=conn.createStatement();
// mod.setnumrow(0) -> 초기화
rs=stmt.executeQuery("select sawon_no, sawon_name, to_char(sawon_ibsail,'YYYY-MM-DD') sawon_ibsail, sawon_sex " +
"from sawon, buser where buser_no(+) = buser_num and " +
"nvl(buser_name,'임시직') = '"+ mod.getValueAt(tab.getSelectedRow(), tab.getSelectedColumn())+"'");
while(rs.next()) {
String s_no=rs.getString("sawon_no");
String s_name=rs.getString("sawon_name");
String s_ibsa=rs.getString("sawon_ibsail");
String s_sex=rs.getString("sawon_sex");
String imsi[]={s_no, s_name, s_ibsa, s_sex};
mod2.addRow(imsi);
}
} catch (Exception ex) {
JOptionPane.showMessageDialog(this, "SQL오류1:"+ex);
}finally{
try{
rs.close(); stmt.close();
}catch (Exception e) {
JOptionPane.showMessageDialog(this, "SQL닫음오류:"+e);
}
}
}
public void display() {
mod=new DefaultTableModel(data,title);
mod2=new DefaultTableModel(data2,title2);
tab=new JTable(mod);
tab2=new JTable(mod2);
JLabel jl=new JLabel("부서정보");
JPanel pn1=new JPanel();
pn1.setLayout(new GridLayout(2,1));
JPanel pn2=new JPanel(new BorderLayout());
JPanel pn3=new JPanel();
pn3.setLayout(new BorderLayout());
pn2.add("North", jl);
pn2.add("Center", new JScrollPane(tab));
jl=new JLabel("직원정보");
pn3.add("North", jl);
pn3.add("Center", new JScrollPane(tab2));
pn1.add(pn2);
pn1.add(pn3);
this.getContentPane().add(pn1, "Center");
this.setBounds(200, 200, 400, 400);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void accDb() {
try {
pool = DBConnectionMgr.getInstance();
} catch (Exception e) {
System.out.println("커넥션 오류: " + e);
}
try {
conn = pool.getConnection(); // 이렇게 하면 연결 까지 완료 됨.
} catch (Exception e) {
System.out.println("객체 생성 오류: " + e);
}
}
public static void main(String[] args) {
new JTableMon1();
}
}
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.table.*;
import javax.swing.*;
import pac.DBConnectionMgr;
public class JTableMon1 extends JFrame{
Object data[][]=new String[0][4];
Object data2[][]=new String[0][4];
DBConnectionMgr pool;
Connection conn;
Statement stmt;
ResultSet rs;
DefaultTableModel mod, mod2; // 테이블 데이타 모델을 클래스를 선언한다.
JTable tab, tab2;
String title[]={"부서번호", "부서명", "부서전화", "위치"};
String title2[]={"사번", "이름", "입사일", "성별"};
public JTableMon1() {
accDb();
display();
accSql();
tab.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent ea) {
// 객체 얻기
JTable tab=(JTable)ea.getComponent(); //<- 받아온 객체를 테이블에 받아옴
if(tab.getSelectedColumn()==1) {
accDsql();
}
}
});
}
public void accSql() {
try {
stmt=conn.createStatement();
// mod.setnumrow(0) -> 초기화
rs=stmt.executeQuery("select * from buser");
while(rs.next()) {
String b_no=rs.getString("buser_no");
String b_name=rs.getString("buser_name");
String b_tel=rs.getString("buser_tel");
String b_loc=rs.getString("buser_loc");
String imsi[]={b_no, b_name, b_tel, b_loc};
mod.addRow(imsi);
}
String im[]={"00","임시직","00-000-0000","기타"};
mod.addRow(im);
} catch (Exception ex) {
JOptionPane.showMessageDialog(this, "SQL오류1:"+ex);
}finally{
try{
rs.close(); stmt.close();
}catch (Exception e) {
JOptionPane.showMessageDialog(this, "SQL닫음오류:"+e);
}
}
}
public void accDsql() {
mod2.setRowCount(0);
try {
stmt=conn.createStatement();
// mod.setnumrow(0) -> 초기화
rs=stmt.executeQuery("select sawon_no, sawon_name, to_char(sawon_ibsail,'YYYY-MM-DD') sawon_ibsail, sawon_sex " +
"from sawon, buser where buser_no(+) = buser_num and " +
"nvl(buser_name,'임시직') = '"+ mod.getValueAt(tab.getSelectedRow(), tab.getSelectedColumn())+"'");
while(rs.next()) {
String s_no=rs.getString("sawon_no");
String s_name=rs.getString("sawon_name");
String s_ibsa=rs.getString("sawon_ibsail");
String s_sex=rs.getString("sawon_sex");
String imsi[]={s_no, s_name, s_ibsa, s_sex};
mod2.addRow(imsi);
}
} catch (Exception ex) {
JOptionPane.showMessageDialog(this, "SQL오류1:"+ex);
}finally{
try{
rs.close(); stmt.close();
}catch (Exception e) {
JOptionPane.showMessageDialog(this, "SQL닫음오류:"+e);
}
}
}
public void display() {
mod=new DefaultTableModel(data,title);
mod2=new DefaultTableModel(data2,title2);
tab=new JTable(mod);
tab2=new JTable(mod2);
JLabel jl=new JLabel("부서정보");
JPanel pn1=new JPanel();
pn1.setLayout(new GridLayout(2,1));
JPanel pn2=new JPanel(new BorderLayout());
JPanel pn3=new JPanel();
pn3.setLayout(new BorderLayout());
pn2.add("North", jl);
pn2.add("Center", new JScrollPane(tab));
jl=new JLabel("직원정보");
pn3.add("North", jl);
pn3.add("Center", new JScrollPane(tab2));
pn1.add(pn2);
pn1.add(pn3);
this.getContentPane().add(pn1, "Center");
this.setBounds(200, 200, 400, 400);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void accDb() {
try {
pool = DBConnectionMgr.getInstance();
} catch (Exception e) {
System.out.println("커넥션 오류: " + e);
}
try {
conn = pool.getConnection(); // 이렇게 하면 연결 까지 완료 됨.
} catch (Exception e) {
System.out.println("객체 생성 오류: " + e);
}
}
public static void main(String[] args) {
new JTableMon1();
}
}