반응형
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92 |
import java.sql.*;
import java.util.*;
public class Db_test {
Connection con = null;
Statement stmt = null;
void up(String p,String d){
try{
String sql = "UPDATE zipcode SET bunji='"+d+"' WHERE zipcode='"+p+"'";
stmt.executeUpdate(sql);
System.out.println("Up ok");
stmt.close(); con.close();
}catch(Exception e){
System.out.println("Up error"+e);
}
}
void del(String post){
try{
String sql="delete from zipcode where zipcode='"+post+"'";
stmt.executeUpdate(sql);
System.out.println("del Ok");
stmt.close(); con.close();
}catch(Exception e){
System.out.println("del error"+e);
}
}
Db_test(){
try{
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","hr","1234");
stmt = con.createStatement();
System.out.println("mssql jdbc test: connect ok!!");
}catch( Exception e ) {
System.out.println(e);
}
}
Vector find(String s){
Vector<String> v = new Vector<String>();
try{
String sql = "select * from zipcode where dong like '%"+s+"%'";
ResultSet rs = stmt.executeQuery(sql);
while(rs.next()){
String s0 = "";
String s1 = rs.getString("zipcode");
String s2 = rs.getString("sido");
String s3 = rs.getString("gugun");
String s4 = rs.getString("dong");
String s5 = rs.getString("bunji");
s0 = s1+ " " + s2 + " "+s3+ " " + s4 + " " + s5;
v.add(s0);
}
System.out.println("find ok");
stmt.close(); con.close();
}catch(Exception e){
System.out.println("find error"+e);
}
return v;
}
public static void main(String ar[]){
new Db_test();
}
}
|
cs |
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125 |
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
import java.util.*;
public class Post extends JFrame{
JLabel l; JList li; JTextField tf,tf2; JButton b,b2,b3;
Post(){
super("우편번호 검색");
l=new JLabel("검색"); tf=new JTextField(7);
tf2=new JTextField();
b=new JButton("find");
b2=new JButton("del");
b3=new JButton("update");
b2.addActionListener(new del());
b3.addActionListener(new up());
b.addActionListener(new find());
// b.addActionListener(new find());
String s[]={" ","","","",""};
li=new JList(s);
li.addMouseListener(new mo());
JScrollPane jp=new JScrollPane(li);
JPanel p=new JPanel(); p.setLayout(new FlowLayout());
p.add(l);p.add(tf); p.add(b);p.add(b2);p.add(b3);
this.setLayout(new BorderLayout());
this.add("North",p);
this.add("Center",jp);
this.add("South",tf2);
this.setDefaultCloseOperation(3);
this.setSize(500,300);
this.setVisible(true);
}
class mo implements MouseListener{
public void mouseClicked(MouseEvent e) {
String st = (String)li.getSelectedValue();
tf2.setText(st);
tf2.setBackground(Color.GREEN);
}
public void mousePressed(MouseEvent e) {}
public void mouseReleased(MouseEvent e) {}
public void mouseEntered(MouseEvent e) {}
@Override
public void mouseExited(MouseEvent e) {}
}
class up implements ActionListener{
public void actionPerformed(ActionEvent e) {
String st = (String)li.getSelectedValue();
String d = tf2.getText();
String sr[] = st.split(" ");
new Db_test().up(sr[0],d); //123-456
String s = tf.getText(); // 양재
Vector<String> v = new Vector<String>();
v = new Db_test().find(s);
li.setListData(v);
}
}
class del implements ActionListener{
public void actionPerformed(ActionEvent e) {
String d= tf2.getText();
if (d.length()>8)
{
String sr[] = d.split(" ");
new Db_test().del(sr[0]); //123-456
String s = tf.getText(); // 양재
Vector<String> v = new Vector<String>();
v = new Db_test().find(s);
li.setListData(v);
}
}
}
class find implements ActionListener{
public void actionPerformed(ActionEvent e) {
String s = tf.getText(); // 양재
Vector<String> v = new Vector<String>();
v = new Db_test().find(s);
li.setListData(v);
}
}
public static void main(String[] args) {
new Post();
}
}
|
cs |
반응형
'프로그래밍 > 시스템' 카테고리의 다른 글
[java - OracleDB 연동] 주문하고 치킨먹자 (0) | 2017.06.05 |
---|---|
[윈도우 프로그래밍] 뮤텍스 크리티컬섹션 (0) | 2017.06.02 |
[윈도우 프로그래밍] 스레드(thread) (0) | 2017.05.25 |
[윈도우 프로그래밍] 다이얼로그박스 만들기 (0) | 2017.05.19 |
[C] 확률 맞추기 프로그램 (0) | 2017.05.18 |