




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、 學(xué)生管理系統(tǒng)java實(shí)現(xiàn) 準(zhǔn)備的軟件,我用是eclipse.exe,MySql,還有mysql jdbc 5.0 數(shù)據(jù)庫。網(wǎng)上很容易找到華軍上就有的。 第一步,安裝eclipse.exe,MySql。MySql的密碼請?jiān)O(shè)置為123,因?yàn)槲业某绦蛏系拿艽a就是123。以后你看懂了可以修改的! 把下載的mysql jdbc 5.0 數(shù)據(jù)庫.zip通常是個壓縮包解壓到一個地方。然后運(yùn)行eclipse.exe。 建立個項(xiàng)目,名字自己隨便叫即可。然后在菜單欄上Project就是Run旁邊的那個菜單,按下左鍵選擇Properties就是最下面的一項(xiàng)。選擇Java Build Path。在對話框的右面出現(xiàn)個
2、小窗體,選Libraries。選擇Add External JARs.。選擇你mysql jdbc 5.0 數(shù)據(jù)庫,解壓出來的mysql-connector-java-5.0.0-beta-bin.jar 也許名字有出入。 如下面的圖 添加完成后就是這個樣子了 第二步 安裝Mysql數(shù)據(jù)庫 請把密碼設(shè)置為123 就是帶password的地方。我的程序上密碼設(shè)置就是123為了運(yùn)行方便。 執(zhí)行下面四個步驟Mysql然后運(yùn)行 。 四部的命令分別是 1。create database scxdb; 2。use scxdb; 3。create table student( number int, nam
3、e char(8), language int, math int, english int, birthday date); 4。insert into student values(1717,曹操,80,90,20,1985-01-01); 下面是程序清單! /= 第一部分 package DBTest; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing
4、.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JScrollPane; import javax.swing.JTable; public class DBFrame /* * param args */ public static void main(String args) / TODO Auto-generated method stub String sql = select * from student; / sql=insert into student values / (1717,張?jiān)骑L(fēng),56,80,65
5、,1979-02-16); DBFrameWindow db = new DBFrameWindow(sql); db.setDefaultCloseOperation(db.EXIT_ON_CLOSE); db.setVisible(true); db.setResizable(false); class DBFrameWindow extends JFrame public DBFrameWindow(String sql) super.setTitle(DBFrameWindow); this.sql=sql; this.setSize(500, 380); JTable table =
6、 DBHander.getTable(this.sql); scroolPane = new JScrollPane(table); this.add(scroolPane); / = JMenu runMenu = new JMenu(Run); JMenuBar mb = new JMenuBar(); mb.add(runMenu); this.setJMenuBar(mb); /=Append=Append= JMenuItem appendItem = new JMenuItem(Append); appendItem.addActionListener(new ActionList
7、ener() Override public void actionPerformed(ActionEvent e) / TODO Auto-generated method stub appendFrame af = new appendFrame(); af.setDefaultCloseOperation(af.EXIT_ON_CLOSE); af.setVisible(true); af.setResizable(false); DBHander.getUpdataTest(); ); /=Append=Append= /=Remove=Remove= JMenuItem remove
8、Item = new JMenuItem(Remove); removeItem.addActionListener(new ActionListener() Override public void actionPerformed(ActionEvent arg0) / TODO Auto-generated method stub removeFrame rf=new removeFrame(); rf.setDefaultCloseOperation(rf.EXIT_ON_CLOSE); rf.setResizable(false); rf.setVisible(true); ); /=
9、Remove=Remove= /=Update=Update= JMenuItem updateItem = new JMenuItem(Update); updateItem.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) / TODO Auto-generated method stub updateFrame uf = new updateFrame(); uf.setDefaultCloseOperation(uf.EXIT_ON_CLOSE); uf.setResiza
10、ble(false); uf.setVisible(true); ); /=Update=Update= /=Find=Find= JMenuItem findItem = new JMenuItem(Find); findItem.addActionListener(new ActionListener() Override public void actionPerformed(ActionEvent arg0) / TODO Auto-generated method stub selectFrame sf = new selectFrame(); sf.setDefaultCloseO
11、peration(sf.EXIT_ON_CLOSE); sf.setResizable(false); sf.setVisible(true); ); /=Find=Find= JMenuItem refreshItem = new JMenuItem(Refresh); refreshItem.addActionListener(new ActionListener() Override public void actionPerformed(ActionEvent arg0) / TODO Auto-generated method stub JTable ta=DBHander.getT
12、able(select * from student;); JScrollPane scroolPane_1=new JScrollPane(ta); add(scroolPane_1); System.out.println(efreshItem); ); runMenu.add(appendItem); runMenu.add(removeItem); runMenu.add(updateItem); runMenu.add(findItem); runMenu.add(refreshItem); / = private JScrollPane scroolPane = null; pri
13、vate String sql=; /= /= 第二部分 package DBTest; import java.io.UnsupportedEncodingException; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.sql.Statement; import javax.swing.JTable; i
14、mport com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource; public class DBHander /* * param args */ public static void main(String args) / TODO Auto-generated method stub String sql = insert into student values (1717,張?jiān)骑L(fēng),56,80,65,1979-02-16); Connection conn = getConnection(); if (conn = nul
15、l) System.out.println(conn=null); else System.out.println(conn!=null); Statement stat = getStatement(); if (stat = null) System.out.println(stat=null); else System.out.println(stat!=null); ResultSet rs = getResult(select * from student;); if (rs = null) System.out.println(s=null); else System.out.pr
16、intln(s!=null); JTable table = getTable(select * from student;); if (rs = null) System.out.println(able=null); else System.out.println(able!=null); private static String select=null; / = Connection = public static Connection getConnection() MysqlConnectionPoolDataSource ds = new MysqlConnectionPoolD
17、ataSource(); ds.setUrl(jdbc:MySQL:/localhost/scxdb); ds.setUser(oot); ds.setPassword(S); try return ds.getConnection(); catch (SQLException e) / TODO Auto-generated catch block e.printStackTrace(); System.out.println(conn=null); return null; / = Connection = / = Statement = public static Statement g
18、etStatement() Connection conn = DBHander.getConnection(); try return conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); catch (SQLException e) / TODO Auto-generated catch block e.printStackTrace(); System.out.println(stat=null); return null; / = Statement = / = Resu
19、ltSet = public static ResultSet getResult(String sql) try return getStatement().executeQuery(sql); catch (SQLException e) / TODO Auto-generated catch block e.printStackTrace(); System.out.println(able=null); return null; / = ResultSet = / = getTable = public static JTable getTable(String sql) Result
20、Set rs = null; String str = null; int cols = 0; try rs = getResult(sql); ResultSetMetaData md = rs.getMetaData(); cols = md.getColumnCount(); int n = 0; while (rs.next() n = n + 1; str = new Stringncols; catch (SQLException e) / TODO Auto-generated catch block e.printStackTrace(); rs = getResult(sql
21、); int n = 0; try while (rs.next() for (int i = 0; i cols; i+) / strni=rs.getString(i+1); strni = new String(rs.getString(i + 1).getBytes( iso-8859-1), GBK); n = n + 1; catch (SQLException e) / TODO Auto-generated catch block e.printStackTrace(); catch (UnsupportedEncodingException e) / TODO Auto-ge
22、nerated catch block e.printStackTrace(); String s = new String Number, Name, Language, Math, English, Birthday ; JTable table = new JTable(str, s); for (int i = 0; i str.length; i+) for (int j = 0; j stri.length; j+) System.out.print(strij + ); System.out.println(); select=str; return table; / = get
23、Table = public static void getUpdataTest(String sql) try Connection conn=getConnection(); if(conn=null) System.out.println(ull); PreparedStatement ps=conn.prepareStatement(UPDATE student SET number = ? WHERE number=?;); ps.setString(1,_x0010_88); ps.setString(2,y7); System.out.println(#); catch (SQL
24、Exception e) / TODO Auto-generated catch block e.printStackTrace(); / = getUpdata = public static void getUpdate(String sql) Statement stat; try stat = getConnection().createStatement(); int n = stat.executeUpdate(sql); System.out.println(* + n + *); catch (SQLException e) / TODO Auto-generated catc
25、h block e.printStackTrace(); / = getUpdata = / = getSelect = public static String getSelect(String sql) getTable(sql); if(select=null) System.out.println(select=null); return select; / = getSelect = /= /= 第3部分 package DBTest; import java.awt.BorderLayout; import java.awt.GridLayout; import java.awt.
26、event.ActionEvent; import java.awt.event.ActionListener; import java.io.UnsupportedEncodingException; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; public class appendFrame extends JFrame /* * param args */
27、 public static void main(String args) / TODO Auto-generated method stub appendFrame af = new appendFrame(); af.setDefaultCloseOperation(af.EXIT_ON_CLOSE); af.setVisible(true); public appendFrame() super.setTitle(AppendFrame); this.setSize(150, 220); JPanel panel = new JPanel(); panel.setLayout(new G
28、ridLayout(6, 2); panel.add(new JLabel( 學(xué)號), tf_num); panel.add(tf_num); ), tf_name); 姓名 panel.add(new JLabel( panel.add(tf_name); panel.add(new JLabel( 語文), tf_c); panel.add(tf_c); panel.add(new JLabel( 數(shù)學(xué)), tf_m); panel.add(tf_m); panel.add(new JLabel( 外語), tf_e); panel.add(tf_e); panel.add(new JLa
29、bel( 生日), tf_b); panel.add(tf_b); tf_c.setText( tf_m.setText( tf_e.setText( this.add(panel, BorderLayout.CENTER); JPanel p = new JPanel(); p.setLayout(new GridLayout(1, 2); p.add(smitButton); / = returnButton = returnButton.addActionListener(new ActionListener() Override public void actionPerformed(
30、ActionEvent arg0) / TODO Auto-generated method stub appendFrame.this.setVisible(false); appendFrame.this.setEnabled(false); ); p.add(returnButton); / = returnButton = / = smitButton / = smitButton.addActionListener(new ActionListener() Override / 本應(yīng)該在此處添加判斷是否為空紀(jì)錄的,然后有對話框彈出但是,沒有想到好的省事的方法,不過是可以實(shí)現(xiàn)的! pu
31、blic void actionPerformed(ActionEvent e) / TODO Auto-generated method stub String t1 = + tf_num.getText() + ,; String t2 = + tf_name.getText() + ,; String t3 = + tf_c.getText() + ,; String t4 = + tf_m.getText() + ,; String t5 = + tf_e.getText() + ,; String t6 = + tf_b.getText() + ; sql = insert into
32、 student values( + t1 + t2 + t3 + t4 + t5 + t6 + ); try sql = new String(sql.getBytes(GBK), iso8859-1); catch (UnsupportedEncodingException e1) / TODO Auto-generated catch block e1.printStackTrace(); System.out.println( + sql); DBHander.getUpdate(sql); appendFrame.this.setVisible(false); appendFrame
33、.this.setEnabled(false); ); / = smitButton / = this.add(p, BorderLayout.SOUTH); public String getSql() return sql; private JTextField tf_num = new JTextField(10); private JTextField tf_name = new JTextField(10); private JTextField tf_c = new JTextField(10); private JTextField tf_m = new JTextField(1
34、0); private JTextField tf_e = new JTextField(10); private JTextField tf_b = new JTextField(16); 瀠楲慶整?畂瑴湯猠業(yè)?瑵潴?敮?瑵潴?確認(rèn)); 瀠楲慶整?畂瑴湯爠瑥牽?瑵潴?敮?瑵潴?返回); private String sql = null; /= /= 第4部分 package DBTest; import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener
35、; import java.io.UnsupportedEncodingException; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTextField; public class removeFrame extends JFrame /* * par
36、am args */ public static void main(String args) / TODO Auto-generated method stub removeFrame rf = new removeFrame(); rf.setDefaultCloseOperation(rf.EXIT_ON_CLOSE); rf.setVisible(true); private JComboBox comboBox_condition = null; private JComboBox comboBox_field = null; private JTextField text_str
37、= new JTextField(10); 瀠楲慶整?畂瑴湯猠業(yè)?瑵潴?敮?瑵潴?確定); 瀠楲慶整?畂瑴湯爠瑥牽?瑵潴?敮?瑵潴?返回); private JCheckBox cBox = new JCheckBox(ALL); private String sql = ; public removeFrame() super.setTitle(RemoveFrame); this.setSize(410, 160); setResizable(false); String strCondition = new String , =, ; String strField = new Stri
38、ng Number, Name, Language, Math, English, Birthday; comboBox_condition = new JComboBox(strCondition); comboBox_field = new JComboBox(strField); JPanel panel = new JPanel(); / panel.setLayout(new GridLayout(2,3); panel.add(comboBox_field); panel.add(comboBox_condition); panel.add(text_str); panel.add
39、(cBox); / =cBox= cBox.addActionListener(new ActionListener() Override public void actionPerformed(ActionEvent arg0) / TODO Auto-generated method stub if (cBox.isSelected() comboBox_field.setEnabled(false); comboBox_condition.setEnabled(false); text_str.setEditable(false); / sql=delete from student;
40、else comboBox_field.setEnabled(true); comboBox_condition.setEnabled(true); text_str.setEditable(true); ); / =cBox= / =smitButton= smitButton.addActionListener(new ActionListener() Override public void actionPerformed(ActionEvent arg0) if (text_str.getText().equals() ?灝楴湯慐敮獻(xiàn)潨?獥慳敧楄污杯渨汵?尠條件不能為空); else
41、String t1 = (String) comboBox_field.getSelectedItem(); String t2 = (String) comboBox_condition.getSelectedItem(); String t3 = +text_str.getText()+; sql = delete from student where + t1 + t2 + t3; try sql=new String(sql.getBytes(GBK),iso8859-1); catch (UnsupportedEncodingException e) / TODO Auto-gene
42、rated catch block e.printStackTrace(); if (cBox.isSelected() sql = delete from student; System.out.println(sql); DBHander.getUpdate(sql); /else ); / =smitButton= /=returnButton= returnButton.addActionListener(new ActionListener() Override public void actionPerformed(ActionEvent arg0) / TODO Auto-gen
43、erated method stub removeFrame.this.setVisible(false); removeFrame.this.setEnabled(false); ); /=returnButton= JPanel p = new JPanel(); p.add(smitButton); p.add(returnButton); this.add(panel, BorderLayout.NORTH); this.add(p, BorderLayout.SOUTH); /= /= 第5部分 package DBTest; import java.awt.BorderLayout; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.UnsupportedEncodingException; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JComboBox; im
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 湖南高爾夫旅游職業(yè)學(xué)院《公共建筑設(shè)計(jì)原理A》2023-2024學(xué)年第二學(xué)期期末試卷
- 昌吉學(xué)院《寫意基礎(chǔ)》2023-2024學(xué)年第二學(xué)期期末試卷
- 湖北三峽職業(yè)技術(shù)學(xué)院《眼耳鼻咽喉口腔科護(hù)理學(xué)》2023-2024學(xué)年第二學(xué)期期末試卷
- 晉中師范高等??茖W(xué)?!吨袑W(xué)政治教育新進(jìn)展》2023-2024學(xué)年第二學(xué)期期末試卷
- 江西工程學(xué)院《嵌入式開發(fā)技術(shù)》2023-2024學(xué)年第二學(xué)期期末試卷
- 廣東食品藥品職業(yè)學(xué)院《生物微課制作》2023-2024學(xué)年第二學(xué)期期末試卷
- 齊魯理工學(xué)院《航空法規(guī)》2023-2024學(xué)年第二學(xué)期期末試卷
- 武漢工程職業(yè)技術(shù)學(xué)院《環(huán)境流體力學(xué)》2023-2024學(xué)年第二學(xué)期期末試卷
- 貴州師范大學(xué)《房屋建筑學(xué)》2023-2024學(xué)年第二學(xué)期期末試卷
- 商標(biāo)使用權(quán)轉(zhuǎn)讓合同(三):長期合作
- 家校共育之道
- DeepSeek入門寶典培訓(xùn)課件
- 西安2025年陜西西安音樂學(xué)院專職輔導(dǎo)員招聘2人筆試歷年參考題庫附帶答案詳解
- 《作文中間技巧》課件
- 廣東省2025年中考物理仿真模擬卷(深圳)附答案
- 2025屆八省聯(lián)考 新高考適應(yīng)性聯(lián)考英語試題(原卷版)
- 新蘇教版一年級下冊數(shù)學(xué)第1單元第3課時《8、7加幾》作業(yè)
- 2024年山東電力高等專科學(xué)校高職單招職業(yè)技能測驗(yàn)歷年參考題庫(頻考版)含答案解析
- 《平面廣告賞析》課件
- 人教鄂教版六年級下冊科學(xué)全冊知識點(diǎn)
- (正式版)HGT 22820-2024 化工安全儀表系統(tǒng)工程設(shè)計(jì)規(guī)范
評論
0/150
提交評論