1、学生管理系统java实现学生管理系统java实现准备的软件,我用是 eclipse.exe, MySql,还有mysql jdbc 5.0数据库。网上很容易找到华 军上就有的。第一步,安装 eclipse.exe, MySql。 MySql的密码请设置为 123,因为我的程序上的密码就是123。以后你看懂了可以修改的!把下载的mysql jdbc 5.0数据库.zip通常是个压缩包解压到一个地方。然后运行 eclipse.exe。建立个项目,名字自己随便叫即可。然后在菜单栏上 Project就是Run旁边的那个菜单,按 下左键选择Properties就是最下面的一项。选择 Java Build
2、 Path。在对话框的右面出现个小 窗体,选Libraries。选择 Add External JARs.。选择你 mysql jdbc 5.0 数据库,解压出来的 mysql-c onn ector-java-5.0.0-beta-b in .jar 也许名字有出入。如下面的图添加完成后就是这个样子了第二步 安装Mysql数据库 请把密码设置为123就是带password的地方。我的程序上密 码设置就是123为了运行方便。然后运行Mysql执行下面四个步骤贏 MySQL Command Line ClientEn teP *7e leone to the JISQL nanitor, Gom
3、nAnd end wit our* MySQL connect ion id is 15Seiner vers ion : S _ 0_6?-coinniuriity-nt tlySQIr Gommurrype Jhelp;* or h for help, Type y to eleccreate datscxdb;nsqi / rnieql ruitsql nysql rnsql mysql mysql use scxdb;nysqT?Lyeql rnysijLy create table studentK nvmbep irit, - nne charf LAnguasfe int, rt
4、ath lnt - enlish int, - birthdav dat&;.ijitih4 elwirigilUiert 坯切 ttvdent TiWe许LW J fft”初9出 J 即J沾阳刖 l Jt .四部的命令分别是1。 create database scxdb;2。 use scxdb;3。 create table student( nu mber int,n ame char(8),Ian guage int,math int, english int, birthday date);4。insert into student values(1717,曹操,80,90,20,
5、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.JMenuBar;import javax.swing.JMenuItem;import javax.swing.JScrollPane;import javax.swing.JTable;public class DBFrame /
6、* param args*/public static void main(String args) / TODO Auto-generated method stubString sql = select * from student;/ sql=insert into student values/ (1717,张云风 ,56,80,65,1979-02-16);DBFrameWindow db = new DBFrameWindow(sql); db.setDefaultCloseOperation(db.EXIT_ON_CLOSE); db.setVisible(true);db.se
7、tResizable(false);class DBFrameWindow extends JFrame public DBFrameWindow(String sql) super.setTitle(DBFrameWindow); this.sql=sql;this.setSize(500, 380);JTable table = DBHander.getTable(this.sql);scroolPane = new JScrollPane(table); this.add(scroolPane);/ =JMenu runMenu = new JMenu(Run);JMenuBar mb
8、= new JMenuBar();mb.add(runMenu);this.setJMenuBar(mb); /=Append=Append= JMenuItem appendItem = new JMenuItem(Append); appendItem.addActionListener(new ActionListener() Overridepublic void actionPerformed(ActionEvent e) / TODO Auto-generated method stub appendFrame af = new appendFrame(); af.setDefau
9、ltCloseOperation(af.EXIT_ON_CLOSE); af.setVisible(true);af.setResizable(false); DBHander.getUpdataTest(););/=Append=Append=/=Remove=Remove= JMenuItem removeItem = new JMenuItem(Remove);removeItem.addActionListener(new ActionListener()Overridepublic void actionPerformed(ActionEvent arg0) / TODO Auto-
10、generated method stub removeFrame rf=new removeFrame(); rf.setDefaultCloseOperation(rf.EXIT_ON_CLOSE); rf.setResizable(false);rf.setVisible(true););/=Remove=Remove=/=Update=Update JMenuItem updateItem = new JMenuItem(Update); updateItem.addActionListener(new ActionListener()public void actionPerform
11、ed(ActionEvent e) / TODO Auto-generated method stub updateFrame uf = new updateFrame(); uf.setDefaultCloseOperation(uf.EXIT_ON_CLOSE); uf.setResizable(false);uf.setVisible(true););/=Update=Update=/=Find=Find= JMenuItem findItem = new JMenuItem(Find);findItem.addActionListener(new ActionListener()Ove
12、rridepublic void actionPerformed(ActionEvent arg0) / TODO Auto-generated method stub selectFrame sf = new selectFrame(); sf.setDefaultCloseOperation(sf.EXIT_ON_CLOSE); sf.setResizable(false);sf.setVisible(true););/=Find=Find= JMenuItem refreshItem = new JMenuItem(Refresh); refreshItem.addActionListe
13、ner(new ActionListener() Overridepublic void actionPerformed(ActionEvent arg0) / TODO Auto-generated method stubJTable ta=DBHander.getTable(select * from student;); JScrollPane scroolPane_1=new JScrollPane(ta);add(scroolPane_1);System.out.println(refreshItem););runMenu.add(appendItem); runMenu.add(r
14、emoveItem);runMenu.add(updateItem); runMenu.add(findItem);runMenu.add(refreshItem);/ = private JScrollPane scroolPane = null; private String sql=;/=/=第二部分package DBTest;import java.io.UnsupportedEncodingException;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSet;
15、import java.sql.ResultSetMetaData;import java.sql.SQLException;import java.sql.Statement;import javax.swing.JTable;import com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource;public class DBHander /* param args*/public static void main(String args) / TODO Auto-generated method stubString sql
16、= insert into student values (1717, 张云风 ,56,80,65,1979-02-16); Connection conn = getConnection();if (conn = null) 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);Res
17、ultSet rs = getResult(select * from student;);if (rs = null) System.out.println(rs=null); else System.out.println(rs!=null);JTable table = getTable(select * from student;); if (rs = null) System.out.println(table=null); else System.out.println(table!=null);private static String select=null;/ = Conne
18、ction = public static Connection getConnection() MysqlConnectionPoolDataSource ds = new MysqlConnectionPoolDataSource(); ds.setUrl(jdbc:MySQL:/localhost/scxdb);ds.setUser(root); ds.setPassword(123);try return ds.getConnection(); catch (SQLException e) / TODO Auto-generated catch block e.printStackTr
19、ace(); System.out.println(conn=null);return null;/ = Connection/ = Statement public static Statement getStatement() Connection conn = DBHander.getConnection();try return conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDA TABLE); catch (SQLException e) / TODO Auto-generated
20、catch blocke.printStackTrace();System.out.println(stat=null);return null;/ = Statement/ = ResultSetpublic static ResultSet getResult(String sql) try return getStatement().executeQuery(sql); catch (SQLException e) / TODO Auto-generated catch block e.printStackTrace();System.out.println(table=null);re
21、turn null;/ = ResultSet/ = getTable public static JTable getTable(String sql) ResultSet 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
22、e) / TODO Auto-generated catch block e.printStackTrace();rs = getResult(sql);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.p
23、rintStackTrace(); catch (UnsupportedEncodingException e) / TODO Auto-generated 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.prin
24、t(strij + );System.out.println();select=str;return table;/ = getTable =public static void getUpdataTest(String sql)try Connection conn=getConnection();if(conn=null) System.out.println(null);? WHEREPreparedStatement ps=conn.prepareStatement(UPDA TE student SET number = number=?;);ps.setString(1,2088)
25、;ps.setString(2,1717);System.out.println(#); catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace();/ = getUpdata = public static void getUpdate(String sql) Statement stat;try stat = getConnection().createStatement();int n = stat.executeUpdate(sql);System.out.println(* + n + *);
26、 catch (SQLException e) / TODO Auto-generated catch block e.printStackTrace();/ = getUpdata/ = getSelectpublic 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.event.ActionEvent;import java.awt.event.ActionListener;import java.io.UnsupportedEncodingException;im
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1