学生信息管理系统+SQL数据库

更新时间:2023-05-04 20:14:01 阅读量: 实用文档 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

本人亲自做的,不需要做任何修改即可顺利运行,sql 表也与程序无缝连接,没有未识别部分。

Sql 表如下:CREATE TABLE STU( 学号varchar(14) PRIMARY KEY, 姓名varchar(8) NOT NULL, 密码varchar(8) NOT NULL, 班级varchar(14) NOT NULL , 性别varchar(2), 学校varchar(14) NOT NULL);

CREATE TABLE TCH( 用户名varchar(8) NOT NULL, 密码varchar(8) NOT NULL );

CREATE TABLE成绩表( 学号varchar(14) PRIMARY KEY, 计算机网络varchar(8) NOT NULL, 汽车概论varchar(8) NOT NULL, 初级日语varchar(8) NOT NULL, 接口技术varchar(8) NOT NULL, ava 程序设计varchar(8) NOT NULL, 数据库varchar(8) NOT NULL, 大学物理varchar(8) NOT NULL);

源程序代码:import java.awt.*; import javax.swing.*; import java.awt.event.*; import java.sql.*;

public class systems extends JFrame implements ActionListener {

static systems ss;

JPanel panel = new JPanel();

JLabel label1 = new JLabel(" 输入姓名:"); JTextField name = new JTextField();

JLabel label2 = new JLabel(" 密码:");

JPasswordField pwd = new JPasswordField(); JButton Enter = new JButton(" 登录");

JButton Exit = new JButton(" 退出");

String url = "D:\\Systems\\title.jpg"; ButtonGroup bgp = new ButtonGroup();

JRadioButton stu = new JRadioButton(" 学生");

JRadioButton tch = new JRadioButton("

教师");

public systems()

{

super(" 登录系统"); this.setResizable(false);

JLabel img = new JLabel(new ImageIcon(url)); img.setBounds(0,0,500,100);

panel.add(img);

stu.setBounds(165,210,70,20);

tch.setBounds(265,210,70,20); bgp.add(stu);

bgp.add(tch);

panel.add(stu);

panel.add(tch);

Enter.setBounds(150,250,80,20);

Exit.setBounds(270,250,80,20);

Enter.addActionListener(this);

Exit.addActionListener(this); panel.add(Enter); panel.add(Exit); panel.setLayout(null);

this.add(panel); label1.setBounds(135,130,100,25);

panel.add(label1);

name.setBounds(265,130,100,25);

panel.add(name); label2.setBounds(135,165,100,25);

panel.add(label2);

pwd.setBounds(265,165,100,25);

panel.add(pwd); this.setBounds(100,100,500,350); this.setVisible(true);

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }

public void actionPerformed(ActionEvent e)

{

if(e.getSource()==Enter)

{

String username , password;

username = name.getText();

password = pwd.getText();

try

{

Class.forName("oracle.jdbc.driver.OracleDriver");

}

catch (ClassNotFoundException ce)

{

JOptionPane.showMessageDialog(ss,ce.getMessage());

} if(stu.isSelected())

{

try

{

Connection con

DriverManager.getConnection("jdbc:oracle:thin:@user29:1521:XE","hr","oracle"); Statement

stmt = con.createStatement();

ResultSet rs = stmt.executeQuery("select * from STU");

while(rs.next())

{

if((rs.getString(" 学

").equals(username))&&(rs.getString(" 密码").equals(password)))

{

JOptionPane.showMessageDialog(ss," 登陆成功"); Students

stu = new Students();

}

else

{

JOptionPane.showMessageDialog(ss," 登录失败");

}

}

rs.close(); stmt.close();

}

catch (SQLException se)

{

JOptionPane.showMessageDialog(ss,se.getMessage());

}

}

else if(tch.isSelected())

{

try

{

Connection con

DriverManager.getConnection("jdbc:oracle:thin:@user29:1521:XE","hr","oracle");

Statement stmt = con.createStatement();

ResultSet rs = stmt.executeQuery("select * from TCH");

本文来源:https://www.bwwdw.com/article/7a4e.html

Top