Java实现医院管理系统

时间:2022-09-23 09:43:40

本文实例为大家分享了java实现医院管理系统的具体代码,供大家参考,具体内容如下

1.开发工具

netbeans8.2
mysql5.7
mysql-connector-java-5.1.6.jar

2.演示

登录界面

Java实现医院管理系统

增删查改界面

Java实现医院管理系统

3.源码

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
create table user (
username varchar(255) not null,
password varchar(255) default null,
primary key (username)
) engine=innodb default charset=utf8;
 
create table doctor_info (
no varchar(45) not null,
name varchar(45) default null,
departments varchar(45) default null,
level varchar(45) default null,
ghf varchar(45) default null,
primary key (no)
) engine=innodb default charset=utf8;
?
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
package 经典增删查改;
import com.mysql.jdbc.connection;
import java.sql.resultset;
import java.sql.sqlexception;
import java.sql.statement;
import java.util.logging.level;
import java.util.logging.logger;
import javax.swing.jcombobox;
import javax.swing.joptionpane;
 
 
public class login extends javax.swing.jframe {
 
 private int flag;
 public login() {
  initcomponents();
 }
 
 /**
 * this method is called from within the constructor to initialize the form.
 * warning: do not modify this code. the content of this method is always
 * regenerated by the form editor.
 */
 @suppresswarnings("unchecked")
 // <editor-fold defaultstate="collapsed" desc="generated code">      
 private void initcomponents() {
 
  jlabel1 = new javax.swing.jlabel();
  jlabel2 = new javax.swing.jlabel();
  jtextfield2 = new javax.swing.jtextfield();
  jpasswordfield1 = new javax.swing.jpasswordfield();
  jbutton2 = new javax.swing.jbutton();
  jbutton3 = new javax.swing.jbutton();
 
  setdefaultcloseoperation(javax.swing.windowconstants.exit_on_close);
 
  jlabel1.settext("账号");
 
  jlabel2.settext("密码");
 
  jtextfield2.settext(" ");
 
  jbutton2.settext("登录");
  jbutton2.addactionlistener(new java.awt.event.actionlistener() {
   public void actionperformed(java.awt.event.actionevent evt) {
    jbutton2actionperformed(evt);
   }
  });
 
  jbutton3.settext("退出");
  jbutton3.addactionlistener(new java.awt.event.actionlistener() {
   public void actionperformed(java.awt.event.actionevent evt) {
    jbutton3actionperformed(evt);
   }
  });
 
  javax.swing.grouplayout layout = new javax.swing.grouplayout(getcontentpane());
  getcontentpane().setlayout(layout);
  layout.sethorizontalgroup(
   layout.createparallelgroup(javax.swing.grouplayout.alignment.leading)
   .addgroup(layout.createsequentialgroup()
    .addgap(103, 103, 103)
    .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.trailing)
     .addcomponent(jlabel2)
     .addcomponent(jlabel1))
    .addpreferredgap(javax.swing.layoutstyle.componentplacement.unrelated)
    .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.trailing, false)
     .addgroup(layout.createsequentialgroup()
      .addcomponent(jbutton2)
      .addpreferredgap(javax.swing.layoutstyle.componentplacement.related, 35, short.max_value)
      .addcomponent(jbutton3))
     .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.leading, false)
      .addcomponent(jtextfield2, javax.swing.grouplayout.default_size, 149, short.max_value)
      .addcomponent(jpasswordfield1)))
    .addcontainergap(114, short.max_value))
  );
  layout.setverticalgroup(
   layout.createparallelgroup(javax.swing.grouplayout.alignment.leading)
   .addgroup(layout.createsequentialgroup()
    .addgap(69, 69, 69)
    .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.baseline)
     .addcomponent(jlabel1)
     .addcomponent(jtextfield2, javax.swing.grouplayout.preferred_size, javax.swing.grouplayout.default_size, javax.swing.grouplayout.preferred_size))
    .addpreferredgap(javax.swing.layoutstyle.componentplacement.unrelated)
    .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.baseline)
     .addcomponent(jlabel2, javax.swing.grouplayout.preferred_size, 26, javax.swing.grouplayout.preferred_size)
     .addcomponent(jpasswordfield1, javax.swing.grouplayout.preferred_size, javax.swing.grouplayout.default_size, javax.swing.grouplayout.preferred_size))
    .addgap(18, 18, 18)
    .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.baseline)
     .addcomponent(jbutton2)
     .addcomponent(jbutton3))
    .addcontainergap(49, short.max_value))
  );
 
  pack();
 }// </editor-fold>     
 
 private void jbutton3actionperformed(java.awt.event.actionevent evt) {          
  system.exit(0);
 }         
 
 private void jbutton2actionperformed(java.awt.event.actionevent evt) {          
  try {
   connection con = dbconnection.getconnection();
   statement stmt = con.createstatement();
   string sql="select *from user";
   resultset rs = stmt.executequery(sql);
   string usename=jtextfield2.gettext().trim();
   char[] p=jpasswordfield1.getpassword();
   string pwd=new string(p);
   string name = null;
   string pass = null;
   while(rs.next()){
    name=rs.getstring(1);
    pass=rs.getstring(2);
    if(usename.equals(name)&&pwd.equals(pass)){
     system.out.println("登录成功!!");
 
     new doctorinfogui().setvisible(true);
     this.dispose();
 
    }
    }
 
 
  } catch (classnotfoundexception ex) {
   logger.getlogger(login.class.getname()).log(level.severe, null, ex);
  } catch (sqlexception ex) {
   logger.getlogger(login.class.getname()).log(level.severe, null, ex);
  }
 }         
 
 /**
 * @param args the command line arguments
 */
 public static void main(string args[]) {
  /* set the nimbus look and feel */
  //<editor-fold defaultstate="collapsed" desc=" look and feel setting code (optional) ">
  /* if nimbus (introduced in java se 6) is not available, stay with the default look and feel.
  * for details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  */
  try {
   for (javax.swing.uimanager.lookandfeelinfo info : javax.swing.uimanager.getinstalledlookandfeels()) {
    if ("nimbus".equals(info.getname())) {
     javax.swing.uimanager.setlookandfeel(info.getclassname());
     break;
    }
   }
  } catch (classnotfoundexception ex) {
   java.util.logging.logger.getlogger(login.class.getname()).log(java.util.logging.level.severe, null, ex);
  } catch (instantiationexception ex) {
   java.util.logging.logger.getlogger(login.class.getname()).log(java.util.logging.level.severe, null, ex);
  } catch (illegalaccessexception ex) {
   java.util.logging.logger.getlogger(login.class.getname()).log(java.util.logging.level.severe, null, ex);
  } catch (javax.swing.unsupportedlookandfeelexception ex) {
   java.util.logging.logger.getlogger(login.class.getname()).log(java.util.logging.level.severe, null, ex);
  }
  //</editor-fold>
 
  /* create and display the form */
  java.awt.eventqueue.invokelater(new runnable() {
   public void run() {
    new login().setvisible(true);
   }
  });
 }
 
 // variables declaration - do not modify     
 private javax.swing.jbutton jbutton2;
 private javax.swing.jbutton jbutton3;
 private javax.swing.jlabel jlabel1;
 private javax.swing.jlabel jlabel2;
 private javax.swing.jpasswordfield jpasswordfield1;
 private javax.swing.jtextfield jtextfield2;
 // end of variables declaration    
}
?
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
package 经典增删查改;
import java.awt.event.keyevent;
 
import javax.swing.joptionpane;
public class doctorinfogui extends javax.swing.jframe {
 public doctorinfogui() {
  initcomponents();
  string sql="select*from doctor_info";
  //doctorinfo看作为一个tablemodel
  doctorinfo d=new doctorinfo (sql);
  //教你如何添加数据的方法
  jtable1.setmodel(d);
  system.out.println(" 已经给表添加好了数据!");
 }
 
 
 private void initcomponents() {
 
  jtfseacher = new javax.swing.jtextfield();
  jbtseacher = new javax.swing.jbutton();
 ///////////////////////////////////////////////////////////////////
   //alt+enter
  jbtseacher.setmnemonic(keyevent.vk_enter);
 
 
  jscrollpane1 = new javax.swing.jscrollpane();
  jscrollpane2 = new javax.swing.jscrollpane();
  jtable1 = new javax.swing.jtable();
  jlabel1 = new javax.swing.jlabel();
  jlabel2 = new javax.swing.jlabel();
  jlabel3 = new javax.swing.jlabel();
  jlabel4 = new javax.swing.jlabel();
  jlabel5 = new javax.swing.jlabel();
  jtfno = new javax.swing.jtextfield();
  jtfname = new javax.swing.jtextfield();
  jtextfieldks = new javax.swing.jtextfield();
  jtflevel = new javax.swing.jtextfield();
  jtfghf = new javax.swing.jtextfield();
  jbtadd = new javax.swing.jbutton();
  updatajbt = new javax.swing.jbutton();
  jbtupdata = new javax.swing.jbutton();
  jlabel6 = new javax.swing.jlabel();
  deletejbt = new javax.swing.jbutton();
  jbtclear = new javax.swing.jbutton();
  jlabel7 = new javax.swing.jlabel();
 
 
  setdefaultcloseoperation(javax.swing.windowconstants.exit_on_close);
 
  jbtseacher.settext("查询");
  jtfseacher.settooltiptext("按姓名查询");
  jbtseacher.addactionlistener(new java.awt.event.actionlistener() {
   public void actionperformed(java.awt.event.actionevent evt) {
    jbtseacheractionperformed(evt);
   }
  });
 
 
  jtable1.addmouselistener(new java.awt.event.mouseadapter() {
   public void mouseclicked(java.awt.event.mouseevent evt) {
    jtable1mouseclicked(evt);
   }
  });
  jscrollpane2.setviewportview(jtable1);
 
  jscrollpane1.setviewportview(jscrollpane2);
 
  jlabel1.settext("编号");
 
  jlabel2.settext("姓名");
 
  jlabel3.settext("科室");
 
  jlabel4.settext("级别");
 
  jlabel5.settext("挂号费");
 
  jtfno.settext(" ");
 
  jtfname.settext(" ");
 
 
  jtflevel.settext(" ");
 
  jtfghf.settext(" ");
 
  jbtadd.settext("添加");
  jbtadd.addactionlistener(new java.awt.event.actionlistener() {
   public void actionperformed(java.awt.event.actionevent evt) {
    jbtaddactionperformed(evt);
   }
  });
 
  updatajbt.settext("修改");
  updatajbt.addactionlistener(new java.awt.event.actionlistener() {
   public void actionperformed(java.awt.event.actionevent evt) {
    updatajbtactionperformed(evt);
   }
  });
 
 
  jlabel6.settext("姓名");
 
  deletejbt.settext("删除");
  deletejbt.addactionlistener(new java.awt.event.actionlistener() {
   public void actionperformed(java.awt.event.actionevent evt) {
    deletejbtactionperformed(evt);
   }
  });
 
  jbtclear.settext("清空");
  jbtclear.addactionlistener(new java.awt.event.actionlistener() {
   public void actionperformed(java.awt.event.actionevent evt) {
    jbtclearactionperformed(evt);
   }
  });
 
  jlabel7.settext("科室");
 
  jtextfieldks.settext(" ");
 
  javax.swing.grouplayout layout = new javax.swing.grouplayout(getcontentpane());
  getcontentpane().setlayout(layout);
  layout.sethorizontalgroup(
   layout.createparallelgroup(javax.swing.grouplayout.alignment.leading)
   .addgroup(layout.createsequentialgroup()
    .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.leading)
     .addgroup(layout.createsequentialgroup()
      .addcontainergap()
      .addcomponent(jscrollpane1, javax.swing.grouplayout.default_size, 515, short.max_value))
     .addgroup(layout.createsequentialgroup()
      .addgap(81, 81, 81)
      .addcomponent(jtfseacher, javax.swing.grouplayout.preferred_size, 78, javax.swing.grouplayout.preferred_size)
      .addgap(39, 39, 39)
      .addcomponent(jbtseacher)
      .addgap(32, 32, 32)
      .addcomponent(deletejbt))
     .addgroup(layout.createsequentialgroup()
      .addcontainergap()
      .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.leading)
       .addgroup(layout.createsequentialgroup()
        .addcomponent(jlabel1)
        .addpreferredgap(javax.swing.layoutstyle.componentplacement.related)
        .addcomponent(jtfno, javax.swing.grouplayout.preferred_size, 76, javax.swing.grouplayout.preferred_size))
       .addgroup(layout.createsequentialgroup()
        .addcomponent(jlabel6)
        .addpreferredgap(javax.swing.layoutstyle.componentplacement.related)
        .addcomponent(jtfname, javax.swing.grouplayout.preferred_size, 76, javax.swing.grouplayout.preferred_size)))
      .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.leading)
       .addgroup(layout.createsequentialgroup()
        .addgap(32, 32, 32)
        .addcomponent(jlabel4)
        .addpreferredgap(javax.swing.layoutstyle.componentplacement.related)
        .addcomponent(jtflevel, javax.swing.grouplayout.preferred_size, 74, javax.swing.grouplayout.preferred_size))
       .addgroup(layout.createsequentialgroup()
        .addgap(18, 18, 18)
        .addcomponent(jlabel5)
        .addpreferredgap(javax.swing.layoutstyle.componentplacement.related)
        .addcomponent(jtfghf, javax.swing.grouplayout.preferred_size, 74, javax.swing.grouplayout.preferred_size)))
      .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.leading)
       .addgroup(layout.createsequentialgroup()
        .addgap(55, 55, 55)
        .addcomponent(jbtupdata))
       .addgroup(layout.createsequentialgroup()
        .addgap(30, 30, 30)
        .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.leading)
         .addgroup(layout.createsequentialgroup()
          .addcomponent(jlabel7)
          .addpreferredgap(javax.swing.layoutstyle.componentplacement.related)
          .addcomponent(jtextfieldks, javax.swing.grouplayout.preferred_size, 65, javax.swing.grouplayout.preferred_size))
         .addgroup(layout.createsequentialgroup()
          .addcomponent(jbtadd)
          .addgap(10, 10, 10)
          .addcomponent(jbtclear)
          .addpreferredgap(javax.swing.layoutstyle.componentplacement.unrelated)
          .addcomponent(updatajbt)))))))
    .addcontainergap())
   .addgroup(layout.createsequentialgroup()
    .addcontainergap()
    .addcomponent(jlabel3)
    .addpreferredgap(javax.swing.layoutstyle.componentplacement.related)
    .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.leading)
     .addcomponent(jlabel2))));
 
 
  layout.setverticalgroup(
   layout.createparallelgroup(javax.swing.grouplayout.alignment.leading)
   .addgroup(layout.createsequentialgroup()
    .addgap(17, 17, 17)
    .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.baseline)
     .addcomponent(jtfseacher, javax.swing.grouplayout.preferred_size, javax.swing.grouplayout.default_size, javax.swing.grouplayout.preferred_size)
     .addcomponent(jbtseacher)
     .addcomponent(deletejbt))
    .addpreferredgap(javax.swing.layoutstyle.componentplacement.unrelated)
    .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.leading)
     .addcomponent(jscrollpane1, javax.swing.grouplayout.preferred_size, 172, javax.swing.grouplayout.preferred_size)
     .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.baseline)
      .addcomponent(jlabel3, javax.swing.grouplayout.preferred_size, 37, javax.swing.grouplayout.preferred_size)
 
      .addcomponent(jbtupdata)))
    .addpreferredgap(javax.swing.layoutstyle.componentplacement.related)
    .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.leading)
     .addgroup(layout.createsequentialgroup()
      .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.baseline)
       .addcomponent(jlabel1)
       .addcomponent(jlabel4)
       .addcomponent(jtfno, javax.swing.grouplayout.preferred_size, javax.swing.grouplayout.default_size, javax.swing.grouplayout.preferred_size)
       .addcomponent(jtflevel, javax.swing.grouplayout.preferred_size, javax.swing.grouplayout.default_size, javax.swing.grouplayout.preferred_size)
       .addcomponent(jlabel7)
       .addcomponent(jtextfieldks, javax.swing.grouplayout.preferred_size, javax.swing.grouplayout.default_size, javax.swing.grouplayout.preferred_size))
      .addgap(8, 8, 8)
      .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.baseline)
       .addcomponent(jlabel5)
       .addcomponent(jtfname, javax.swing.grouplayout.preferred_size, javax.swing.grouplayout.default_size, javax.swing.grouplayout.preferred_size)
       .addcomponent(jtfghf, javax.swing.grouplayout.preferred_size, javax.swing.grouplayout.default_size, javax.swing.grouplayout.preferred_size)
       .addcomponent(jlabel6))
      .addpreferredgap(javax.swing.layoutstyle.componentplacement.related)
      .addcomponent(jlabel2, javax.swing.grouplayout.preferred_size, 0, javax.swing.grouplayout.preferred_size)
      .addcontainergap(39, short.max_value))
     .addgroup(javax.swing.grouplayout.alignment.trailing, layout.createsequentialgroup()
      .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.trailing)
       .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.baseline)
        .addcomponent(jbtclear)
        .addcomponent(updatajbt))
       .addcomponent(jbtadd, javax.swing.grouplayout.alignment.leading))
      .addgap(43, 43, 43))))
  );
 
  pack();
 }// </editor-fold>     
 
 private void jbtseacheractionperformed(java.awt.event.actionevent evt) {          
   string text=jtfseacher.gettext().trim();
   //重新执行查询sql语句,在读取数据,然后再添加到table表格中,实现刷新表格的作用
   string sql="select*from doctor_info where name='"+text+"'";
   doctorinfo d=new doctorinfo (sql);
   jtable1.setmodel(d);
   jtfseacher.settext("");
 
 
 }          
 
 private void jbtaddactionperformed(java.awt.event.actionevent evt) {         
   string no=jtfno.gettext().trim();
   string name=jtfname.gettext().trim();
   string ks= jtextfieldks.gettext().trim();
   string level=jtflevel.gettext().trim();
   string ghf=jtfghf.gettext().trim();
 
   //执行添加sql语句,再读取数据
   string sql = "insert into doctor_info(no,name ,departments,level,ghf) values('" + no + "','" + name+ "', '" + ks+ "', '" + level + "','"+ghf+"')";
   doctorinfo df=new doctorinfo ();
   df.add(sql);
   //
   //重新读取数据
   string sql1="select*from doctor_info";
   doctorinfo d=new doctorinfo (sql1);
   jtable1.setmodel(d);
 
   jtfno.settext("");
   jtfname.settext("");
   jtflevel.settext("");
   jtfghf.settext("");
   jtextfieldks.settext("");
 }         
 
 private void updatajbtactionperformed(java.awt.event.actionevent evt) {          
  //获取当前位置
  int index = jtable1.getselectedrow();
  //获取莫一行的第0列的值,注意获取的行数需要减少一个
  string id = jtable1.getvalueat(index-1, 0).tostring() ;
 
  string no=jtfno.gettext().trim();
  string name=jtfname.gettext().trim();
  string ks= jtextfieldks.gettext().trim();
  string level=jtflevel.gettext().trim();
  string ghf=jtfghf.gettext().trim();
 
 
  jtfno.settext("");
  jtfname.settext("");
  jtflevel.settext("");
  jtfghf.settext("");
  jtextfieldks.settext("");
 
  string sql = "update doctor_info set name ='" + name + "',departments='" + ks + "',level='" + level+ "',ghf='" + ghf + "' where no='" + no+ "'";
  system.out.println(id);
  system.out.println(no);
  doctorinfo df=new doctorinfo ();
  df.update(sql);
 
 
  //重新读取数据
  string sql1="select*from doctor_info";
  doctorinfo d=new doctorinfo (sql1);
  jtable1.setmodel(d);
 
 
 }         
 
 
 private void jtable1mouseclicked(java.awt.event.mouseevent evt) {         
  //获取某一行的具体值,并把它显示在文本框中
  string no = jtable1.getvalueat(jtable1.getselectedrow(), 0).tostring();
  string name = jtable1.getvalueat(jtable1.getselectedrow(), 1).tostring();
  string ks = jtable1.getvalueat(jtable1.getselectedrow(), 2).tostring();
  string level = jtable1.getvalueat(jtable1.getselectedrow(), 3).tostring();
  string ghf= jtable1.getvalueat(jtable1.getselectedrow(), 4).tostring();
  //把点击的内容显示在文本框中
  jtfno.settext(no);
  jtfname.settext(name);
  jtextfieldks.settext(ks);
  jtflevel.settext(level);
  jtfghf.settext(ghf);
 
 
 }        
 
 private void deletejbtactionperformed(java.awt.event.actionevent evt) {          
   //设置选择对话框的选项         
  string[] options = {"是", "否"};
  int answ = joptionpane.showoptiondialog(null, "是否确认删除??", "提示", joptionpane.yes_no_cancel_option, joptionpane.question_message, null, options, options[1]);
 
  if (answ == 0) {
   int index = jtable1.getselectedrow();
   string id = jtable1.getvalueat(index, 0).tostring();
   string sql="delete from doctor_info where no='"+id+"'";
 
   // 删除一条记录
   doctorinfo df=new doctorinfo ();
   df.delete(sql);
   system.out.println("删除成功!!!");
 
   //重新读取数据
   string sql1="select*from doctor_info";
   doctorinfo d=new doctorinfo (sql1);
    jtable1.setmodel(d);
 
    jtfno.settext("");
    jtfname.settext("");
    jtflevel.settext("");
    jtfghf.settext("");
    jtextfieldks.settext("");
 
   } else
   {
    joptionpane.showmessagedialog(null, "无法删除!!!");
   }
 }         
 
 private void jbtclearactionperformed(java.awt.event.actionevent evt) {          
   jtfno.settext("");
   jtfname.settext("");
   jtflevel.settext("");
   jtfghf.settext("");
   jtextfieldks.settext("");
 }         
 
 public static void main(string args[]) {
  /* set the nimbus look and feel */
  //<editor-fold defaultstate="collapsed" desc=" look and feel setting code (optional) ">
  /* if nimbus (introduced in java se 6) is not available, stay with the default look and feel.
   * for details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
   */
  try {
   for (javax.swing.uimanager.lookandfeelinfo info : javax.swing.uimanager.getinstalledlookandfeels()) {
    if ("nimbus".equals(info.getname())) {
     javax.swing.uimanager.setlookandfeel(info.getclassname());
     break;
    }
   }
  } catch (classnotfoundexception ex) {
   java.util.logging.logger.getlogger(doctorinfogui.class.getname()).log(java.util.logging.level.severe, null, ex);
  } catch (instantiationexception ex) {
   java.util.logging.logger.getlogger(doctorinfogui.class.getname()).log(java.util.logging.level.severe, null, ex);
  } catch (illegalaccessexception ex) {
   java.util.logging.logger.getlogger(doctorinfogui.class.getname()).log(java.util.logging.level.severe, null, ex);
  } catch (javax.swing.unsupportedlookandfeelexception ex) {
   java.util.logging.logger.getlogger(doctorinfogui.class.getname()).log(java.util.logging.level.severe, null, ex);
  }
  //</editor-fold>
 
  /* create and display the form */
  java.awt.eventqueue.invokelater(new runnable() {
   public void run() {
    new doctorinfogui().setvisible(true);
   }
  });
 }
 
 // variables declaration - do not modify     
 private javax.swing.jbutton updatajbt;
 private javax.swing.jbutton deletejbt;
 private javax.swing.jlabel jlabel1;
 private javax.swing.jlabel jlabel2;
 private javax.swing.jlabel jlabel3;
 private javax.swing.jlabel jlabel4;
 private javax.swing.jlabel jlabel5;
 private javax.swing.jlabel jlabel6;
 private javax.swing.jlabel jlabel7;
 private javax.swing.jscrollpane jscrollpane1;
 private javax.swing.jscrollpane jscrollpane2;
 private javax.swing.jtable jtable1;
 
 private javax.swing.jbutton jbtadd;
 private javax.swing.jbutton jbtclear;
 private javax.swing.jbutton jbtupdata;
 private javax.swing.jbutton jbtseacher;
 private javax.swing.jtextfield jtfghf;
 private javax.swing.jtextfield jtextfieldks;
 private javax.swing.jtextfield jtflevel;
 private javax.swing.jtextfield jtfname;
 private javax.swing.jtextfield jtfno;
 private javax.swing.jtextfield jtfseacher;
 // end of variables declaration    
}
?
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
126
127
128
129
package 经典增删查改;
 
import java.io.serializable;
import java.sql.connection;
import java.sql.preparedstatement;
import java.sql.resultset;
import java.sql.sqlexception;
import java.util.vector;
import java.util.logging.level;
import java.util.logging.logger;
import javax.swing.table.abstracttablemodel;
 
public class doctorinfo extends abstracttablemodel {
  connection con=null;
  preparedstatement ps=null;
  resultset rs=null;
  vector<serializable> rowdata,columnname;
  public doctorinfo(string sql){
   init( sql) ;
  }
 
  public doctorinfo(){
 
  }
  public void init(string sql){
 
    //columnname保存表头信息
    columnname=new vector<serializable>();
    columnname.add("编号");
    columnname.add("姓名");
    columnname.add("科室");
    columnname.add("级别");
    columnname.add("挂号费");
 
 
   //rowdata向量保存每一行的信息
   rowdata=new vector<serializable>();
   try {
   con = dbconnection.getconnection();
    ps=(preparedstatement) con.preparestatement( sql);
    rs=ps.executequery();
   while(rs.next()){
     vector bang=new vector();
     bang.add(rs.getstring(1) );
     bang.add(rs.getstring(2) );
     bang.add(rs.getstring(3) );
     bang.add(rs.getstring(4) );
     bang.add(rs.getstring(5) );
 
     //将读取的每一行数据添加到bang中,然后再把bang添加到rowdata向量中
     rowdata.add(bang);
   }
  } catch (classnotfoundexception e) {
   // todo auto-generated catch block
   e.printstacktrace();
  } catch (sqlexception e) {
   // todo auto-generated catch block
   e.printstacktrace();
  }finally {
   if(con!=null&&ps!=null&rs!=null){
    try {
     con.close();
     ps.close();
     rs.close();
    } catch (sqlexception e) {
 
     e.printstacktrace();
    }
 
   }
  }
 }
 public void chushihua(string sql){
   connection con=null;
   preparedstatement ps=null;
  int rs;
 
  try {
   con = dbconnection.getconnection();
    ps=(preparedstatement) con.preparestatement( sql);
    rs=ps.executeupdate();
 
  } catch (classnotfoundexception e) {
   // todo auto-generated catch block
   e.printstacktrace();
  } catch (sqlexception e) {
   // todo auto-generated catch block
   e.printstacktrace();
  }
 
 
 }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 public void delete(string sql){
  chushihua( sql);
 
 }
 public void add(string sql){
  chushihua( sql);
 
 }
 
 public void update(string sql){
  chushihua( sql);
 
 }
 
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 @override
 public int getrowcount() {
  return this.rowdata.size();
 }
 
 @override
 public int getcolumncount() {
  return this.columnname.size();
 }
 
 @override
 public object getvalueat(int row, int column) {
  return ((vector ) this.rowdata.get(row)).get(column);
 }
 public string getcolumnname(int column) {
 
  return (string) this.columnname.get(column);
 }
 
 
 }
?
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
package 经典增删查改;
import com.mysql.jdbc.connection;
import java.sql.drivermanager;
import java.sql.sqlexception;
import java.util.logging.level;
import java.util.logging.logger;
class dbconnection{
  public static connection getconnection() throws classnotfoundexception {
  // jdbc 驱动名及数据库 url
  string jdbc_driver = "com.mysql.jdbc.driver";
  string url = "jdbc:mysql://localhost:3306/hospital";
  string user = "root";
  string password = "root";
  connection conn = null;
 
   //与数据库建立连接
    class.forname(jdbc_driver);
   try {
    conn= (connection) drivermanager.getconnection(url,user,password);
   system.out.println("已经连接数据库");
 
   } catch (sqlexception ex) {
    logger.getlogger(dbconnection.class.getname()).log(level.severe, null, ex);
   }
 
 
  return conn;
 }
 
}

网上难找一个带界面的管理系统源码,我把这简单管理系统分享出去,希望能够帮助到那些需要帮助的人。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。

原文链接:https://blog.csdn.net/weixin_36279318/article/details/77428339