学生信息管理系统JAVA.doc
《学生信息管理系统JAVA.doc》由会员分享,可在线阅读,更多相关《学生信息管理系统JAVA.doc(13页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、/*/import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;public class DB / public static Connection getConn() / mysqljdbctry Class.forName(com.mysql.jdbc.Driver); catch (ClassNotFoundException e) e.printStackTrace();
2、/ String ip = localhost;String dbName = jdbc;String url = jdbc:mysql:/ + ip + / + dbName;/ mysql jdbcConnection conn = null;try conn = DriverManager.getConnection(url, root, 1234); catch (SQLException e) e.printStackTrace();return conn;public static void close(ResultSet rs) if (rs != null) try rs.cl
3、ose(); catch (SQLException e) e.printStackTrace();public static void close(Statement pstmt) if (pstmt != null) try pstmt.close(); catch (SQLException e) e.printStackTrace();public static void close(Connection conn) if (conn != null) try conn.close(); catch (SQLException e) e.printStackTrace();public
4、 static void rollback(Connection conn) if (conn != null) try conn.rollback(); catch (SQLException e) e.printStackTrace();/*删除类*/import java.sql.Connection;import java.sql.SQLException;import java.sql.Statement;public class Drop public void drop(MainFrame frame, String number, String choice) Connecti
5、on con = null;Statement s = null;con = DB.getConn();try if(number.isEmpty()frame.text.append(关键字不能为空!删除失败!nn);return;s = con.createStatement();String str = delete from student where + choice + = + numbertry s.executeUpdate(str);frame.text.append(删除完成!nn); catch (Exception e) / TODO Auto-generated ca
6、tch blockframe.text.append(删除失败!nn);e.printStackTrace();DB.close(s);DB.close(con); catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace();/*添加类*/import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.SQLException;public class Insert public void insertData(M
7、ainFrame frame, String number, String name,String dept, String grade) / public void insertData() throws SQLException Connection con = null;PreparedStatement s = null;int grades = 0;if (number.isEmpty() | name.isEmpty() frame.text.append(学号或姓名不能为空,插入失败!);return;if(!grade.isEmpty()grades = Integer.par
8、seInt(grade);String str = insert into student values (?,?,?,?);con = DB.getConn();try s = con.prepareStatement(str);s.setString(1, number);s.setString(2, name);s.setString(3, dept);s.setInt(4, grades);try s.executeUpdate();frame.text.append(插入成功!); catch (Exception e) / TODO Auto-generated catch blo
9、ckframe.text.append(插入失败!); catch (SQLException e) DB.close(s);DB.close(con);import java.awt.Button;import java.awt.Choice;import java.awt.Color;import java.awt.FlowLayout;import java.awt.Font;import java.awt.Frame;import java.awt.Graphics;import java.awt.Image;import java.awt.Label;import java.awt.
10、Menu;import java.awt.MenuBar;import java.awt.MenuItem;import java.awt.Panel;import java.awt.TextArea;import java.awt.TextField;import java.awt.Toolkit;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;public c
11、lass MainFrame extends Frame implements ActionListener private static final long serialVersionUID = 1L;private MenuItem select, insert, delete, update;private TextField rescan, scan, number, name, dept, grade;private Panel panel;private Choice choice;private int flag = 0;private MenuBar jmb;TextFiel
12、d username, password, repassword;Button submit, zhuce;TextArea text;public static void main(String args) / TODO Auto-generated method stubMainFrame frame = new MainFrame();frame.frame();/* 创建主窗口*/public void frame() setSize(400, 400);setTitle(学生信息管理);setLocation(400, 200);/ setDefaultCloseOperation(
13、JFrame.EXIT_ON_CLOSE);/ pack();this.addWindowListener(new WindowAdapter() public void windowClosing(WindowEvent e) setVisible(false);System.exit(-1);setResizable(false);setVisible(true);denglu();public void paint(Graphics g) Image image = Toolkit.getDefaultToolkit().getImage(src/welcom.jpg);g.drawIm
14、age(image, 0, 20, 400, 400, this);/* 对窗口的菜单栏标签进行初始化并添加监听*/public void init() panel = new Panel();jmb = new MenuBar();setMenuBar(jmb);Menu file = new Menu(菜单);Menu exit = new Menu(选项);jmb.add(file);jmb.add(exit);(select = new MenuItem(查询);(insert = new MenuItem(添加);(delete = new MenuItem(删除);(update
15、= new MenuItem(修改);exit.add(new MenuItem(退出登陆);exit.add(new MenuItem(返回);exit.addActionListener(this);select.addActionListener(this);insert.addActionListener(this);delete.addActionListener(this);update.addActionListener(this);/* 事件监听 */Overridepublic void actionPerformed(ActionEvent e) / TODO Auto-g
16、enerated method stubString actionCommand = e.getActionCommand();boolean flags = false;if (登陆.equals(actionCommand) flags = new User().isRight(this, username.getText().trim(),password.getText().trim();if (flags) init();this.removeAll();if (注册.equals(actionCommand) addUser();if (提交.equals(actionComman
17、d) flags = false;flags = this.isEmpty(username.getText().trim(), password.getText().trim(), repassword.getText().trim();if (flags) flags = false;flags = new User().addUser(this,username.getText().trim(), password.getText().trim();if(flags)this.removeAll();denglu();if (重置.equals(actionCommand) userna
18、me.setText();password.setText();repassword.setText();if (退出登陆.equals(actionCommand) this.removeAll();this.remove(jmb);denglu();if (返回.equals(actionCommand) this.removeAll();if (查询.equals(actionCommand) selects();flag = 1;if (添加.equals(actionCommand) insert();flag = 2;if (删除.equals(actionCommand) del
19、ete();flag = 3;if (修改.equals(actionCommand) update();flag = 4;if (确定.equals(actionCommand) if (flag = 1) text.setText();new Select().select(this, scan.getText().trim(),choice.getSelectedItem(); else if (flag = 2) text.setText();new Insert().insertData(this, number.getText().trim(), name.getText().tr
20、im(), dept.getText().trim(), grade.getText().trim(); else if (flag = 3) text.setText();new Drop().drop(this, scan.getText().trim(),choice.getSelectedItem();new Select().select(this, , all); else text.setText();new Update().update(this, scan.getText().trim(), rescan.getText().trim(), choice.getSelect
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 学生 信息管理 系统 JAVA
限制150内