您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 质量控制/管理 > java学生成绩管理系统代码
importjavax.swing.*;importjava.awt.*;importjava.awt.event.*;importjava.sql.*;importjavax.swing.*;importjava.awt.*;importjava.awt.event.*;importjava.awt.event.*;importjavax.swing.*;importjava.awt.*;importjava.awt.event.*;importjava.sql.*;importjavax.swing.table.JTableHeader;importjavax.swing.*;importjava.awt.*;importjava.awt.event.*;importjava.sql.*;importjavax.swing.*;importjava.awt.*;importjava.awt.event.*;importjava.sql.*;importjavax.swing.*;importjava.awt.*;importjava.awt.event.*;importjava.sql.*;importjavax.swing.*;importjava.awt.*;importjava.awt.event.*;importjava.sql.*;importjavax.swing.table.DefaultTableModel;importjavax.swing.table.JTableHeader;importjavax.swing.*;importjava.awt.*;importjava.awt.event.*;importjava.sql.*;classAddFormextendsJFrameimplementsActionListener{JLabellabName=newJLabel(学号:);JLabellabDate=newJLabel(出生日期:);JLabellabScore=newJLabel(成绩:);JTextFieldtxtName=newJTextField(20);JTextFieldtxtDate=newJTextField(18);JTextFieldtxtScore=newJTextField(20);JButtonbtnOk=newJButton(确定);JButtonbtnClear=newJButton(清空);JPanelpan=newJPanel();JPanelpan1=newJPanel();JPanelpan2=newJPanel();JPanelpan3=newJPanel();JPanelpan4=newJPanel();Connectioncnn;Statementstm;ResultSetrs;AddForm(){super(添加数据);setSize(400,300);setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);pan.setBorder(BorderFactory.createEtchedBorder());pan1.add(labName);pan1.add(txtName);pan2.add(labDate);pan2.add(txtDate);pan3.add(labScore);pan3.add(txtScore);pan4.add(btnOk);pan4.add(btnClear);pan.setLayout(newGridLayout(3,1));pan.add(pan1);pan.add(pan2);pan.add(pan3);getContentPane().add(pan,Center);getContentPane().add(pan4,South);btnOk.addActionListener(this);btnClear.addActionListener(this);setVisible(true);txtName.requestFocus();}publicvoidactionPerformed(ActionEventae){if(ae.getSource()==btnClear){txtName.setText();txtDate.setText();txtScore.setText();txtName.requestFocus();}elseif(ae.getSource()==btnOk){StringstrName=txtName.getText();StringstrDate=txtDate.getText();StringstrScore=txtScore.getText();if(strName.equals())JOptionPane.showMessageDialog(this,学号不能为空!,警告,JOptionPane.ERROR_MESSAGE);elseif(strDate.equals())JOptionPane.showMessageDialog(this,出生日期不能为空!,警告,JOptionPane.ERROR_MESSAGE);elseif(strScore.equals())JOptionPane.showMessageDialog(this,成绩不能为空!,警告,JOptionPane.ERROR_MESSAGE);else{try{Class.forName(sun.jdbc.odbc.JdbcOdbcDriver);}catch(ClassNotFoundExceptionex){ex.printStackTrace();}try{cnn=DriverManager.getConnection(Jdbc:Odbc:MyDB);stm=cnn.createStatement();}catch(SQLExceptionex){ex.printStackTrace();}try{rs=stm.executeQuery(select*from成绩表where学号='+strName+');if(rs.next()){JOptionPane.showMessageDialog(this,对不起,该成绩信息已存在!);}else//否则插入记录{//System.out.println(insertinto成绩表values('+strName+',#+strDate+#,+strScore+));stm.executeUpdate(insertinto成绩表values('+strName+','+strDate+',+strScore+));JOptionPane.showMessageDialog(null,记录已经成功添加!);}//断开连接stm.close();cnn.close();}catch(SQLExceptionex){System.out.println(SQLException:+ex.getMessage());}}}}publicstaticvoidmain(String[]args){newAddForm();}}classBrowseFormextendsJFrame{String[]str={学号,出生日期,成绩};Object[][]data;JTabletable;JTableHeaderhead;JScrollPanejsp;Connectionconn;Statementstmt;ResultSetrs;BrowseForm(){super(浏览数据);setSize(400,300);inti=0,j=0;introw;try{Class.forName(sun.jdbc.odbc.JdbcOdbcDriver);conn=DriverManager.getConnection(jdbc:odbc:MyDB,,);stmt=conn.createStatement();rs=stmt.executeQuery(selectCOUNT(*)asafrom成绩表);rs.next();row=rs.getInt(a);rs.close();data=newObject[row][3];rs=stmt.executeQuery(select*from成绩表);while(rs.next()){data[i][j++]=rs.getString(学号);data[i][j++]=rs.getDate(出生日期);data[i][j]=newInteger(rs.getInt(成绩));i++;j=0;}table=newJTable(data,str);head=table.getTableHeader();jsp=newJScrollPane(table);getContentPane().add(head,North);getContentPane().add(jsp,Center);rs.close();stmt.close();conn.close();}catch(Exceptione){e.printStackTrace();}setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);setVisible(true);}publicstaticvoidmain(String[]args){newBrowseForm();}}classDeleteFormextendsJFrameimplementsActionListener{JLabellabName=newJLabel(学号:);JLabellabDate=newJLabel(出生日期:);JLabellabScore=newJLabel(成绩:);JTextFieldtxtName=newJTextField(20);JTextFieldtxtDate=newJTextField(18);JTextFieldtxtScore=newJTextField(20);JButtonbtnDel=newJButton(删除);JButtonbtnCancel=newJButton(取消);JButtonbtnQuery=newJButton(查询);JPanelpan=newJPanel();JPanelpan1=newJPanel();JPanelpan2=newJPanel();JPanelpan3=newJPanel();JPanelpan4=newJPanel();Connectioncnn;Statementstm;ResultSetrs;DeleteForm(){super(删除数据);setSize(400,300);setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);pan.setBorder(BorderFactory.createEtchedBorder());pan1.add(labName);pan1.add(txtName);pan2.add(labDate);pan2.add(txtDate);pan3.add(labScore);pan3.add(txtScore);pan4.add(btnQuery);pan4.add(btnDel);pan4.add(btnCancel);pan.setLayout(newGridLayout(3,1));pan.add(pan1);pan.add(pan2);pan.add(pan3);getContentPane().add(pan,Center);getContentPane().add(pan4,South);btnQuery.addActionListener(this);btnDel.addActionListener(this);btnCancel.addAc
本文标题:java学生成绩管理系统代码
链接地址:https://www.777doc.com/doc-6222306 .html