⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 studentmanagement.java

📁 this is a system of student of managemet thouhth it is very small ,it contact a
💻 JAVA
字号:
//StudentManager.java
import java.awt.*;
import javax.swing.*;

import java.awt.event.*;
import java.sql.*;
public class StudentManagement extends JFrame implements ActionListener{
  /**
	 * 
	 */
	private static final long serialVersionUID = 1L;

JTabbedPane dbTabPane;//定义选项卡窗格对象dbTabPane
  
  JPanel inputPanel;//录入面板;
  
  Connection conn;//定义连接接口对象conn
  Statement stmt;//定义执行语句接口对象stmt

  public StudentManagement() {
    super("XXX班学生基本信息管理");
    setGUIComponent();
  }//end StudentManagement method;

  public void setGUIComponent(){
    Container c=getContentPane();
    c.setLayout(new BorderLayout());
    
    
dbTabPane=new JTabbedPane();//创建选项卡窗格对象

    //定义录入面板
    inputPanel=new JPanel();
    inputPanel.setLayout(new FlowLayout());
    JButton inputBtn = new JButton("录入");
    inputBtn.addActionListener(this);
    StudentPanel inputInnerPanel = new StudentPanel();//录入界面面板
    inputPanel.add(inputInnerPanel);
    inputPanel.add(inputBtn);

dbTabPane.add("录入记录",inputPanel);
//将录入面板加入到选项卡窗格dbTabPane的”录入记录”选项卡中;
    
    c.add(BorderLayout.NORTH,dbTabPane);
  }//end of setGUIComponent method;

  public void connection(){//连接数据库;
    try{
      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//装载驱动程序;

      conn=DriverManager.getConnection("jdbc:odbc:ExampleMDBDataSource") ;//连接ODBC数据源studentManager

      stmt=conn.createStatement()  ;//获得执行语句对象stmt;

    }catch(ClassNotFoundException e1){
      System.err.println("驱动程序装载失败!");
    }catch(SQLException e2){
      e2.getSQLState();
      e2.getMessage();
    }
  }//end of connection method;

  public void close(){//关闭数据连接
    try{
     if (stmt != null) stmt.close();
     if (conn != null) conn.close();      
   }catch(SQLException e2){
     System.err.println("不能正常关闭");
   }
  }
  public void inputRecords(){//录入学生记录
  
StudentPanel inputInnerPanel = null;
String no=inputInnerPanel.getNo();//获得学号
  String name=inputInnerPanel.getNames();//获得姓名
  String gendar=inputInnerPanel.getGendar();//获得性别
  String birth=inputInnerPanel.getBirth();//获得出生年月
  String address=inputInnerPanel.getAddress();//获得家庭地址
  String tel=inputInnerPanel.getTel();//获得联系电话;
  
  try{
  connection();
  String InsSQL;
  InsSQL="INSERT INTO student (学号,姓名,性别,出生年月,家庭住址,联系电话)"+
"VALUES("+"'"+no+"',"+"'"+name+"',"+"'"+gendar+"',"+"'"+birth+"',"+"'"+address+"',"+"'"+tel+"')";//定制插入SQL语句字符串 
  stmt.executeUpdate(InsSQL); //代码3;//执行将新记录插入到数据表student中;
  
}catch(SQLException e1){
    System.err.println(e1.getSQLState());
  }
  finally{
   close();//关闭数据库
  }
  }
  public void actionPerformed(ActionEvent e){
    Object inputBtn = null;
	if(e.getSource()==inputBtn){
      inputRecords();
    }
  }

  public static void main(String[] args) {
    StudentManagement sm = new StudentManagement();
    sm.setSize(550,250);
    sm.setVisible(true);
    sm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -