- 项目简介
基于Java Swing+MySQL的学生选课管理系统,支持对课程的发布,查询,添加,删除操作,同时支持对学生及教师信息的管理。
2.项目采用技术
该项目主要使用Java Swing+SQLServer
3.功能需求分析
学生选课管理系统中要实现管理者对于学生和教师信息的管理以及对课程的增删查改操作
4.项目亮点
本次java课程设计用idea连接SQLServer数据库实现两者之间的交互。
5.主要功能代码详解
①LoginWindow.java
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.sql.Connection;
public class LoginWindow extends JFrame{
private static Connection dbConn = null;
//标签
private JLabel lable1;
private JLabel lable2;
//文本框
private JTextField text1;
private JTextField text2;
//按钮
private JButton bt1;
private JButton bt2;
//构造函数
public LoginWindow()
{
this.init();
this.addComponent();
this.addListener();
}
public void init()
{
this.setSize(500,400);
this.setVisible(true);
this.setTitle("登录界面");
this.setLayout(null);
this.setLocation(700, 300);
}
private void addComponent()
{
lable1 = new JLabel("用户名");
lable1.setSize(100,70);
lable1.setLocation(100,80);
this.add(lable1);
lable2 = new JLabel("密 码");
lable2.setSize(100,70);
lable2.setLocation(100,130);
this.add(lable2);
text1 = new JTextField();
text1.setSize(150,30);
text1.setLocation(160,100);
this.add(text1);
text2 = new JTextField();
text2.setSize(150,30);
text2.setLocation(160,150);
this.add(text2);
bt1 = new JButton("登录");
bt1.setSize(70,30);
bt1.setLocation(140,195);
this.add(bt1);
bt2 = new JButton("退出");
bt2.setSize(70,30);
bt2.setLocation(250,195);
this.add(bt2);
this.setBackground(Color.blue);
//设置单击关闭按钮时的默认操作
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
private void addListener()
{
bt1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(text1.getText().equals("001")&&text2.getText().equals("123456"))
//此处假设管理员只有一个 用户名为001 密码为123456
{
new MainWindow();
dispose();
}
else
{
JOptionPane.showMessageDialog(null, "登陆密码错误");
}
}
});
bt2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
dispose();
}
});
}
public static void main(String[] args) {
new LoginWindow();
}
}
②MainWindow.java
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
/*
该程序是管理员对于选课系统的管理
*/
public class MainWindow extends JFrame implements ActionListener {
JButton bt1;
JButton bt2;
JButton bt3;
JButton bt4;
JButton bt5;
JButton bt6;
JPanel panel;
JPanel panel2;
JLabel label;
MainWindow(){
this.setSize(1200, 1000);
this.setTitle("学生选课管理系统");
this.setLayout(null);
this.setLocation(400,200);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
bt1=new JButton("发布课程信息");
bt1.setSize(150, 50);
bt1.setLocation(150, 400);
bt1.addActionListener(this);
bt1.setActionCommand("发布课程信息");
bt2=new JButton("查询课程");
bt2.setSize(150, 50);
bt2.setLocation(150, 500);
bt2.addActionListener(this);
bt2.setActionCommand("查询课程");
bt3=new JButton("删除课程");
bt3.setSize(150, 50);
bt3.setLocation(350, 400);
bt3.addActionListener(this);
bt3.setActionCommand("删除课程");
bt4=new JButton("学生管理");
bt4.setSize(150, 50);
bt4.setLocation(350, 500);
bt4.addActionListener(this);
bt4.setActionCommand("学生管理");
bt5=new JButton("教师管理");
bt5.setSize(150, 50);
bt5.setLocation(550, 400);
bt5.addActionListener(this);
bt5.setActionCommand("教师管理");
this.add(bt1);
this.add(bt2);
this.add(bt3);
this.add(bt4);
this.add(bt5);
panel=new JPanel();
panel.setLocation(100, 20);
panel.setLayout(null);
panel.setBackground(Color.GRAY);
this.add(panel);
panel2=new JPanel();
panel2.setSize(650,350);
panel2.setLocation(100, 20);
panel2.setLayout(null);
panel2.setBackground(Color.lightGray);
label=new JLabel();
label.setText("欢迎登陆课程管理系统");
label.setLocation(165,60);
label.setSize(500, 200);
panel2.add(label);
label.setFont( (new Font("仿宋",Font.BOLD,30)));
this.add(panel2);
panel2.setVisible(true);
this.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
JButton bt=(JButton )e.getSource();
//移除上一个面板
if(bt!=null)
{
this.remove(panel2);
this.remove(panel);
}
if(bt.getText().equals("发布课程信息"))
{
panel=new SubmitCourse();
panel.setLocation(100, 20);
this.add(panel);
this.repaint();
}
else {
if(bt.getText().equals("查询课程"))
{
panel=new FindCourse();
panel.setLocation(100, 20);
this.add(panel);
this.repaint();
}
else {
if(bt.getText().equals("删除课程"))
{
panel=new DeleteCourse();
panel.setLocation(100, 20);
this.add(panel);
this.repaint();
}
else {
if(bt.getText().equals("学生管理"))
{
panel=new AStudent();
panel.setLocation(100, 20);
this.add(panel);
this.repaint();
}
else{
if(bt.getText().equals("教师管理"))
{
panel = new ATeacher();
panel.setLocation(100, 20);
this.add(panel);
this.repaint();
}
}
}
}
}
}
}
③SubmitCourse.java
import java.awt.Color;
import java.sql.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class SubmitCourse extends JPanel implements ActionListener{
JLabel Cnolabel;
JLabel Cnamelabel;
JLabel Creditlabel;
JTextField Cnotext;
JTextField Cnametext;
JTextField Credittext;
JButton Addbt;
JScrollPane scrollpane;
JTable table;
public SubmitCourse() {
this.setSize(650,350);
this.setLocation(100, 20);
this.setLayout(null);
this.setBackground(Color.lightGray);
Cnolabel=new JLabel("请输入课程号");
Cnolabel.setSize(100,30);
Cnolabel.setLocation(60, 20);
this.add(Cnolabel);
Cnotext=new JTextField();
Cnotext.setSize(120,30);
Cnotext.setLocation(180, 20);
this.add(Cnotext);
//--------------------------------------------------
Cnamelabel=new JLabel("请输入课程名称");
Cnamelabel.setSize(100,30);
Cnamelabel.setLocation(60, 60);
this.add(Cnamelabel);
Cnametext=new JTextField();
Cnametext.setSize(120,30);
Cnametext.setLocation(180, 60);
this.add(Cnametext);
//------------------------------------------------------------
Creditlabel=new JLabel("请输入课程学分");
Creditlabel.setSize(100,30);
Creditlabel.setLocation(60, 140);
this.add(Creditlabel);
Credittext=new JTextField();
Credittext.setSize(120,30);
Credittext.setLocation(180, 140);
this.add(Credittext);
this.setVisible(true);
//----------------------------------------------------
Addbt=new JButton("添加");
Addbt.setSize(80,30);
Addbt.setLocation(350, 80);
this.add(Addbt);
Addbt.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent e) {
String addCno=Cnotext.getText();
String addCname=Cnametext.getText();
String addCredit=Credittext.getText();
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
//加载对应的jdbc驱动
String url="jdbc:sqlserver://localhost:1433; DatabaseName=choose_course";
//配置连接字符串
String user="sa";//sa超级管理员
String password="123456";//密码
Connection conn=DriverManager.getConnection(url,user,password);
//创建数据库连接对象
Statement st=conn.createStatement();
//创建SQL语句执行对象
String strSQL="insert into tb_course values('"+addCno+"','"+addCname+"','"+addCredit+"','"+"001"+"')";
String strSQL1="(Select* from tb_course where CourseNum ='"+addCno+"' )";//下面用来判断课程是否存在
if(!addCno.trim().equals("")&&!addCname.trim().equals("")&&!addCredit.trim().equals(""))
{
ResultSet rs1=st.executeQuery(strSQL1);
if(rs1.next())
{
JOptionPane.showMessageDialog(null,"该课程已存在"); }
else {
int rs=st.executeUpdate(strSQL);
if(rs==1) {
JOptionPane.showMessageDialog(null,"课程添加成功");
}
else{
JOptionPane.showMessageDialog(null,"课程添加失败");
}
}
}
else
{ JOptionPane.showMessageDialog(null,"请输入课程信息");
}
conn.close();
//关闭数据库连接
}
catch (ClassNotFoundException ex) {
System.out.println("没有找到对应的数据库驱动类");
}
catch (SQLException ex) {
System.out.println("数据库连接或者是数据库操作失败");
}
}
}
④FindCourse.java
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class FindCourse extends JPanel implements ActionListener{
JLabel Inputlabel;
JTextField Inputtext;
JButton Findbt;
JLabel Cnolabel;
JLabel Cnamelabel;
JLabel Creditlabel;
JTextField Cnotext;
JTextField Cnametext;
JTextField Credittext;
public FindCourse() {
this.setSize(650,350);
this.setLocation(100, 20);
this.setLayout(null);
this.setBackground(Color.lightGray);
Cnolabel=new JLabel("课程号");
Cnolabel.setSize(100,30);
Cnolabel.setLocation(100, 120);
this.add(Cnolabel);
Cnotext=new JTextField();
Cnotext.setSize(120,30);
Cnotext.setLocation(220, 120);
this.add(Cnotext);
Cnamelabel=new JLabel("课程名称");
Cnamelabel.setSize(100,30);
Cnamelabel.setLocation(100, 160);
this.add(Cnamelabel);
Cnametext=new JTextField();
Cnametext.setSize(120,30);
Cnametext.setLocation(220, 160);
this.add(Cnametext);
Creditlabel=new JLabel("课程学分");
Creditlabel.setSize(100,30);
Creditlabel.setLocation(100, 240);
this.add(Creditlabel);
Credittext=new JTextField();
Credittext.setSize(120, 30);
Credittext.setLocation(220, 240);
this.add(Credittext);
Inputlabel=new JLabel("请输入课程号");
Inputlabel.setSize(150,50);
Inputlabel.setLocation(100, 45);
this.add(Inputlabel);
Inputtext=new JTextField();
Inputtext.setSize(160,40);
Inputtext.setLocation(200, 45);
this.add(Inputtext);
Findbt=new JButton("查询");
Findbt.setSize(90,38);
Findbt.setLocation(420, 45);
this.add(Findbt);
Findbt.addActionListener(this);
this.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
String inputName=Inputtext.getText();
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
//加载对应的jdbc驱动
String url="jdbc:sqlserver://localhost:1433; DatabaseName=choose_course";
//配置连接字符串
String user="sa";//sa超级管理员
String password="123456";//密码
Connection conn=DriverManager.getConnection(url,user,password);
//创建数据库连接对象
Statement st=conn.createStatement();
//创建SQL语句执行对象
String strSQL="(Select* from tb_course where CourseNum='"+inputName+"' )";
ResultSet rs=st.executeQuery(strSQL);
if(rs.next())
{
Cnotext.setText(rs.getString(1));
Cnametext.setText(rs.getString(2));
Credittext.setText(rs.getString(3));
}
else
{
JOptionPane.showMessageDialog(null, "您查询的课程不存在,请重新输入");
}
conn.close();
//关闭数据库连接
}
catch (ClassNotFoundException ex) {
System.out.println("没有找到对应的数据库驱动类");
}
catch (SQLException ex) {
System.out.println("数据库连接或者是数据库操作失败");
}
}
}
⑤DeleteCourse.java
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.*;
public class DeleteCourse extends JPanel implements ActionListener{
JLabel Cnolabel;
JTextField Cnotext;
JButton Delbt;
JTable table;
public DeleteCourse() {
this.setSize(650,350);
this.setLocation(100, 20);
this.setLayout(null);
this.setBackground(Color.lightGray);
Cnolabel=new JLabel("输入删除的课程号");
Cnolabel.setSize(150,50);
Cnolabel.setLocation(100, 280);
this.add(Cnolabel);
Cnotext=new JTextField();
Cnotext.setSize(160,40);
Cnotext.setLocation(200, 280);
this.add(Cnotext);
Delbt=new JButton("确认删除");
Delbt.setSize(90,38);
Delbt.setLocation(420, 280);
this.add(Delbt);
Delbt.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent e) {
String delCno=Cnotext.getText();
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
//加载对应的jdbc驱动
String url="jdbc:sqlserver://localhost:1433; DatabaseName=choose_course";
//配置连接字符串
String user="sa";//sa超级管理员
String password="123456";//密码
Connection conn=DriverManager.getConnection(url,user,password);
//创建数据库连接对象
Statement st=conn.createStatement();
//创建SQL语句执行对象
String strSQL="delete from tb_course where CourseNum='"+delCno+"'";
int rs=st.executeUpdate(strSQL);
if(rs==1) {
JOptionPane.showMessageDialog(null,"课程删除成功");
}
else{
JOptionPane.showMessageDialog(null,"课程删除失败");
}
conn.close();
//关闭数据库连接
}
catch (ClassNotFoundException ex) {
System.out.println("没有找到对应的数据库驱动类");
}
catch (SQLException ex) {
System.out.println("数据库连接或者是数据库操作失败");
}
}
}
⑥AStudent.java
import java.awt.Color;
import java.sql.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class AStudent extends JPanel implements ActionListener{
JLabel Snolabel;
JLabel Snamelabel;
JLabel Sbirthlabel;
JLabel Ssexlabel;
JLabel Sdeptlabel;
JLabel Spasswordlabel;
JTextField Snotext;
JTextField Snametext;
JTextField Sbirthtext;
JTextField SSextext;
JTextField Sdepttext;
JTextField Spasswordtext;
JButton Addbt;
JScrollPane scrollpane;
JTable table;
public AStudent() {
this.setSize(1000,850);
this.setLocation(100, 20);
this.setLayout(null);
this.setBackground(Color.lightGray);
Snolabel=new JLabel("请输入学生学号");
Snolabel.setSize(100,30);
Snolabel.setLocation(60, 20);
this.add(Snolabel);
Snotext=new JTextField();
Snotext.setSize(120,30);
Snotext.setLocation(180, 20);
this.add(Snotext);
Snamelabel=new JLabel("请输入学生姓名");
Snamelabel.setSize(100,30);
Snamelabel.setLocation(60, 60);
this.add(Snamelabel);
Snametext=new JTextField();
Snametext.setSize(120,30);
Snametext.setLocation(180, 60);
this.add(Snametext);
Ssexlabel=new JLabel("请输入学生性别");
Ssexlabel.setSize(100,30);
Ssexlabel.setLocation(60, 100);
this.add(Ssexlabel);
SSextext=new JTextField();
SSextext.setSize(120,30);
SSextext.setLocation(180, 100);
this.add(SSextext);
Sdeptlabel=new JLabel("请输入所在系");
Sdeptlabel.setSize(100,30);
Sdeptlabel.setLocation(60, 140);
this.add(Sdeptlabel);
Sdepttext=new JTextField();
Sdepttext.setSize(120,30);
Sdepttext.setLocation(180, 140);
this.add(Sdepttext);
Sbirthlabel=new JLabel("请输入出生日期");
Sbirthlabel.setSize(100,30);
Sbirthlabel.setLocation(60, 180);
this.add(Sbirthlabel);
Sbirthtext=new JTextField();
Sbirthtext.setSize(120,30);
Sbirthtext.setLocation(180, 180);
this.add(Sbirthtext);
Addbt=new JButton("添加");
Addbt.setSize(80,30);
Addbt.setLocation(350, 80);
this.add(Addbt);
Addbt.addActionListener(this);
Spasswordlabel=new JLabel("请输入学生密码");
Spasswordlabel.setSize(100,30);
Spasswordlabel.setLocation(60, 220);
this.add(Spasswordlabel);
Spasswordtext=new JTextField();
Spasswordtext.setSize(120,30);
Spasswordtext.setLocation(180, 220);
this.add(Spasswordtext);
this.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
String addSno=Snotext.getText();
String addSname=Snametext.getText();
String addSsex=SSextext.getText();
String addSbirth=Sbirthtext.getText();
String addSdept=Sdepttext.getText();
String addSpassword=Spasswordtext.getText();
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
//加载对应的jdbc驱动
String url="jdbc:sqlserver://localhost:1433; DatabaseName=choose_course";
//配置连接字符串
String user="sa";//sa超级管理员
String password="123456";//密码
Connection conn=DriverManager.getConnection(url,user,password);
//创建数据库连接对象
Statement st=conn.createStatement();
//创建SQL语句执行对象
String strSQL="insert into tb_student values('"+addSno+"','"+addSname+"','"+addSsex+"','"+addSbirth+"','"+addSpassword+"','"+addSdept+"','"+"001"+"')";
String strSQL1="(Select* from tb_student where StudentNum='"+addSno+"' )";
if(!addSno.trim().equals(""))
{
ResultSet rs1=st.executeQuery(strSQL1);
if(rs1.next())
{
JOptionPane.showMessageDialog(null,"该学生信息已存在"); }
else {
int rs=st.executeUpdate(strSQL);
if(rs==1) {
JOptionPane.showMessageDialog(null,"学生信息添加成功");
}
else{
JOptionPane.showMessageDialog(null,"学生信息添加失败");
}
}
}
else
{ JOptionPane.showMessageDialog(null,"请输入学生信息");
}
conn.close();
//关闭数据库连接
}
catch (ClassNotFoundException ex) {
System.out.println("没有找到对应的数据库驱动类");
}
catch (SQLException ex) {
System.out.println("数据库连接或者是数据库操作失败");
}
}
}
⑦ATeacher.java
import java.awt.Color;
import java.sql.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class ATeacher extends JPanel implements ActionListener{
JLabel Tnolabel;
JLabel Tnamelabel;
JLabel Tbirthlabel;
JLabel Tsexlabel;
JLabel Tdeptlabel;
JLabel Tpasswordlabel;
JLabel Titlelabel;
JTextField Tnotext;
JTextField Tnametext;
JTextField Tbirthtext;
JTextField TSextext;
JTextField Tdepttext;
JTextField Tpasswordtext;
JTextField Titletext;
JButton Addbt;
JScrollPane scrollpane;
JTable table;
public ATeacher() {
this.setSize(1000,850);
this.setLocation(100, 20);
this.setLayout(null);
this.setBackground(Color.lightGray);
Tnolabel=new JLabel("请输入教工号");
Tnolabel.setSize(100,30);
Tnolabel.setLocation(60, 20);
this.add(Tnolabel);
Tnotext=new JTextField();
Tnotext.setSize(120,30);
Tnotext.setLocation(180, 20);
this.add(Tnotext);
Tnamelabel=new JLabel("请输入教师姓名");
Tnamelabel.setSize(100,30);
Tnamelabel.setLocation(60, 60);
this.add(Tnamelabel);
Tnametext=new JTextField();
Tnametext.setSize(120,30);
Tnametext.setLocation(180, 60);
this.add(Tnametext);
Tsexlabel=new JLabel("请输入教师性别");
Tsexlabel.setSize(100,30);
Tsexlabel.setLocation(60, 100);
this.add(Tsexlabel);
TSextext=new JTextField();
TSextext.setSize(120,30);
TSextext.setLocation(180, 100);
this.add(TSextext);
Tdeptlabel=new JLabel("请输入教师所在系");
Tdeptlabel.setSize(100,30);
Tdeptlabel.setLocation(60, 140);
this.add(Tdeptlabel);
Tdepttext=new JTextField();
Tdepttext.setSize(120,30);
Tdepttext.setLocation(180, 140);
this.add(Tdepttext);
Tbirthlabel=new JLabel("请输入出生日期");
Tbirthlabel.setSize(100,30);
Tbirthlabel.setLocation(60, 180);
this.add(Tbirthlabel);
Tbirthtext=new JTextField();
Tbirthtext.setSize(120,30);
Tbirthtext.setLocation(180, 180);
this.add(Tbirthtext);
Addbt=new JButton("添加");
Addbt.setSize(80,30);
Addbt.setLocation(350, 80);
this.add(Addbt);
Addbt.addActionListener(this);
Tpasswordlabel=new JLabel("请输入教师密码");
Tpasswordlabel.setSize(100,30);
Tpasswordlabel.setLocation(60, 220);
this.add(Tpasswordlabel);
Tpasswordtext=new JTextField();
Tpasswordtext.setSize(120,30);
Tpasswordtext.setLocation(180, 220);
this.add(Tpasswordtext);
Titlelabel=new JLabel("请输入教师职称");
Titlelabel.setSize(100,30);
Titlelabel.setLocation(60, 260);
this.add(Titlelabel);
Titletext=new JTextField();
Titletext.setSize(120,30);
Titletext.setLocation(180, 260);
this.add(Titletext);
this.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
String addTno=Tnotext.getText();
String addTname=Tnametext.getText();
String addTsex=TSextext.getText();
String addTbirth=Tbirthtext.getText();
String addTdept=Tdepttext.getText();
String addTpassword=Tpasswordtext.getText();
String addTitle=Titletext.getText();
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
//加载对应的jdbc驱动
String url="jdbc:sqlserver://localhost:1433; DatabaseName=choose_course";
//配置连接字符串
String user="sa";//sa超级管理员
String password="123456";//密码
Connection conn=DriverManager.getConnection(url,user,password);
//创建数据库连接对象
Statement st=conn.createStatement();
//创建SQL语句执行对象
String strSQL="insert into tb_teacher values('"+addTno+"','"+addTdept+"','"+addTname+"','"+addTsex+"','"+addTitle+"','"+addTbirth+"','"+addTpassword+"','"+"001"+"')";
String strSQL1="(Select* from tb_teacher where TeacherNum='"+addTno+"' )";
if(!addTno.trim().equals(""))
{
ResultSet rs1=st.executeQuery(strSQL1);
if(rs1.next())
{
JOptionPane.showMessageDialog(null,"该教师信息已存在"); }
else {
int rs=st.executeUpdate(strSQL);
if(rs==1) {
JOptionPane.showMessageDialog(null,"教师信息添加成功");
}
else{
JOptionPane.showMessageDialog(null,"教师信息添加失败");
}
}
}
else
{ JOptionPane.showMessageDialog(null,"请输入教师信息");
}
conn.close();
//关闭数据库连接
}
catch (ClassNotFoundException ex) {
System.out.println("没有找到对应的数据库驱动类");
}
catch (SQLException ex) {
System.out.println("数据库连接或者是数据库操作失败");
}
}
}
下面给出关于数据库连接测试的部分
对于iDEA连接SQLServer数据库的过程参照:IDEA连接sqlserver数据库_树上灵溪的博客-CSDN博客_idea连接sqlserver数据库
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
public class Test {
private static Connection dbConn = null;
public static void main(String[] args) {
String dbURL = "jdbc:sqlserver://192.168.56.1:1433;DatabaseName=choose_course";
try {
//1.加载驱动
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
System.out.println("加载驱动成功!");
//2.连接
dbConn = DriverManager.getConnection(dbURL, "sa", "123456");
System.out.println("连接数据库成功!");
String sql="select * from tb_student"; //此处选择一个表,从该表中进行选择
PreparedStatement statement=null;
statement=dbConn.prepareStatement(sql);
ResultSet res=null;
res=statement.executeQuery();
while(res.next()){
String title=res.getString("StudentNum"); //此处输出所指定的列
System.out.println(title);
}
}catch(Exception e) {
e.printStackTrace();
System.out.println("连接数据库失败!");
}
}
}
数据库设计部分
数据库中包含4个表,分别为tb_manager、tb_student、tb_teacher、tb_course具体如下图:
6.团队成员负责模块
队长负责LoginWindow和MainWindow界面设计以及DeleteCourse部分,其余两位成员分别负责AStudent、ATeacher和FindCourse、SubmitCourse模块,分工明确,实现效率高。
7.项目git地址文章来源:https://www.toymoban.com/news/detail-465447.html
https://github.com/AyuSunA/OOP.githttps://github.com/AyuSunA/OOP.git文章来源地址https://www.toymoban.com/news/detail-465447.html
到了这里,关于java实现管理学生选课系统的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!