本文實例為大家分享了java swing實現電影購票系統的具體代碼,供大家參考,具體內容如下
首先系統分為前臺用戶登錄注冊和后臺管理員進行管理
項目采用三層架構思想
系統首頁
電影詳情以及查看評論
查看所有電影場次
購買影票選擇座位
查看影票以及點擊進入評論
對購買的影票進行想評論
接下來看看管理員
管理員進行操作,幾個按鈕樣式差不錯,就不全貼了。感覺已經貼的挺詳細的了。
代碼的話就貼一些通用的訪問數據庫的具有通用的增刪改查的代碼。
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
|
/** * 執行增刪改的操作 * @param sql * @param param * @return */ public static boolean operupdate(string sql, list<object> param) { int res = 0 ; // 獲得影響的行數 connection conn = null ; // 獲取連接 preparedstatement psts = null ; // 裝載sql語句 resultset rs = null ; conn = getconn(); try { psts = conn.preparestatement(sql); if (param != null ) { for ( int i = 0 ; i < param.size(); i++) { psts.setobject(i + 1 , param.get(i)); } } res = psts.executeupdate(); } catch (sqlexception e) { e.printstacktrace(); } finally { closeall(rs, psts, conn); //關閉相關的連接 } return res > 0 ? true : false ; } |
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
|
/** * 執行查找的操作 * @param sql * @param param * @return */ public static <t> list<t> operquery(string sql, list<object> param, class <t> cls) { connection conn = null ; // 獲取連接 preparedstatement psts = null ; // 裝載sql語句 resultset rs = null ; conn = getconn(); list<t> list = new arraylist<t>(); try { psts = conn.preparestatement(sql); if (param != null ) { for ( int i = 0 ; i < param.size(); i++) { psts.setobject(i + 1 , param.get(i)); } } rs=psts.executequery(); resultsetmetadata rsmd = rs.getmetadata(); while (rs.next()){ t entity = cls.newinstance(); for ( int j = 0 ;j<rsmd.getcolumncount();j++){ string columnname = rsmd.getcolumnname(j+ 1 ); object value = rs.getobject(columnname); field fields = cls.getdeclaredfield(columnname); fields.setaccessible( true ); fields.set(entity, value); } list.add(entity); } } catch (sqlexception e) { e.printstacktrace(); } catch (instantiationexception e) { e.printstacktrace(); } catch (illegalaccessexception e) { e.printstacktrace(); } catch (nosuchfieldexception e) { e.printstacktrace(); } catch (securityexception e) { e.printstacktrace(); } finally { closeall(rs, psts, conn); } return list; } |
上述兩個方法還是蠻具有通用性的。如有錯誤,希望各位看到的大佬不吝賜教。
下載地址下載
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。
原文鏈接:https://blog.csdn.net/kzw11/article/details/81354777