数据库课程设计(极其简单的学生成绩管理系统)
以前做的学生成绩管理系统,很稀烂。
这个是我大三上学期的时候刚开始学习数据库课程的时候做的一个很稀烂的课程设计的源代码,当时刚刚开始学习Java和Oracle,而且当时就花了今年元旦3天假,做的这个C/S程序中没有加入触发器和存储过程等高级PL/SQL编程,粗糙程度可见一斑。另外由于开始做的时候没注意,有一个致命硬伤:就是没有考虑级联更新的问题,导致有的时候不能删除表中的记录。当然在我这学期在闲下来的时候重新把这些地方都做了修改,因为修改的时候没有改这份文档(这篇文章中所有的代码都是直接从原始文档中复制粘贴的,而且因为我做的时候觉得比较简单,连代码的注释都没加),不过也算是很直观的看出我去年的水平是多么的稀烂。若干年以后,我再来看自己做的这个东西,我应该会笑自己当时为了赶时间做的这个要质量没质量,连很多Java控件都没搞清楚的学生成绩管理系统。
用的后台数据库是:Oracle Database Enterprise Edition Release 10.2.0.1.0。数据库的SID:XSCJ,密码:qazwsx。
堆代码用的IDE:Oracle JDeveloper 11g
以下是数据库中建表以及添加表中数据的SQL脚本,我已经排好顺序,可以一次性运行。
//全部SQL语句
create table student(
sno int not null primary key,
name varchar2(10) not null,
sex varchar2(3) not null,
birthday date not null,
class varchar2(5)
);
create table teacher(
tno int not null primary key,
name varchar2(10) not null,
sex varchar2(3) not null,
birthday date not null,
prof varchar2(8) not null,
depart varchar2(20) not null
);
create table course(
cno varchar2(6) not null primary key,
cname varchar2(20) not null,
tno int not null,
foreign key(tno) references teacher(tno)
);
create table score(
sno int not null,
cno varchar2(6) not null,
degree int,
foreign key(sno) references student(sno),
foreign key(cno) references course(cno)
);
create table users(
userID varchar2(20) primary key,
password varchar2(20) not null,
quanxian int not null,
constraint quanxian_set check(quanxian>=1 and quanxian<=2)
)
insert into users values(
'Derek','123456',2);
insert into users values(
'洪志恒','123456',1);
insert into users values(
'马新星','123456',1);
insert into users values(
'方雨阳','123456',2);
insert into users values(
'董响','123456',2);
insert into student values
(101,'曾华','男',to_date('1987-09-01','YYYY-MM-DD'),'95033');
insert into student values
(102,'匡明','男',to_date('1985-10-02','YYYY-MM-DD'),'95031');
insert into student values
(103,'王丽','女',to_date('1986-02-23','YYYY-MM-DD'),'95033');
insert into student values
(104,'李军','男',to_date('1986-02-02','YYYY-MM-DD'),'95033');
insert into student values
(105,'王芳','女',to_date('1985-02-10','YYYY-MM-DD'),'95031');
insert into student values
(106,'陆君','男',to_date('1984-06-03','YYYY-MM-DD'),'95031');
insert into student values
(107,'李强','男',to_date('1986-02-02','YYYY-MM-DD'),'95033');
insert into student values
(108,'赵红','女',to_date('1985-02-10','YYYY-MM-DD'),'95034');
insert into student values
(109,'张伟','男',to_date('1984-06-03','YYYY-MM-DD'),'95035');
insert into teacher values
(804,'李诚','男',to_date('1968-12-02','YYYY-MM-DD'),'副教授','计算机系');
insert into teacher values
(856,'张旭','男',to_date('1975-09-02','YYYY-MM-DD'),'讲师','电子工程系');
insert into teacher values
(825,'王萍','女',to_date('1978-05-08','YYYY-MM-DD'),'助教','计算机系');
insert into teacher values
(831,'刘冰','女',to_date('1979-08-10','YYYY-MM-DD'),'助教','电子工程系');
insert into course values
('3-105','计算机导论',825);
insert into course values
('3-245','操作系统',804);
insert into course values
('6-166','数字电路',856);
insert into course values
('9-888','高等数学',831);
insert into score values(103,'3-245',86);
insert into score values(105,'3-245',75);
insert into score values(109,'3-245',68);
insert into score values(103,'3-105',92);
insert into score values(105,'3-105',88);
insert into score values(109,'3-105',76);
insert into score values(101,'3-105',64);
insert into score values(107,'3-105',91);
insert into score values(108,'3-105',78);
insert into score values(101,'6-166',85);
insert into score values(107,'6-166',79);
insert into score values(108,'6-166',81);
create table student(
sno int not null primary key,
name varchar2(10) not null,
sex varchar2(3) not null,
birthday date not null,
class varchar2(5)
);
create table teacher(
tno int not null primary key,
name varchar2(10) not null,
sex varchar2(3) not null,
birthday date not null,
prof varchar2(8) not null,
depart varchar2(20) not null
);
create table course(
cno varchar2(6) not null primary key,
cname varchar2(20) not null,
tno int not null,
foreign key(tno) references teacher(tno)
);
create table score(
sno int not null,
cno varchar2(6) not null,
degree int,
foreign key(sno) references student(sno),
foreign key(cno) references course(cno)
);
create table users(
userID varchar2(20) primary key,
password varchar2(20) not null,
quanxian int not null,
constraint quanxian_set check(quanxian>=1 and quanxian<=2)
)
insert into users values(
'Derek','123456',2);
insert into users values(
'洪志恒','123456',1);
insert into users values(
'马新星','123456',1);
insert into users values(
'方雨阳','123456',2);
insert into users values(
'董响','123456',2);
insert into student values
(101,'曾华','男',to_date('1987-09-01','YYYY-MM-DD'),'95033');
insert into student values
(102,'匡明','男',to_date('1985-10-02','YYYY-MM-DD'),'95031');
insert into student values
(103,'王丽','女',to_date('1986-02-23','YYYY-MM-DD'),'95033');
insert into student values
(104,'李军','男',to_date('1986-02-02','YYYY-MM-DD'),'95033');
insert into student values
(105,'王芳','女',to_date('1985-02-10','YYYY-MM-DD'),'95031');
insert into student values
(106,'陆君','男',to_date('1984-06-03','YYYY-MM-DD'),'95031');
insert into student values
(107,'李强','男',to_date('1986-02-02','YYYY-MM-DD'),'95033');
insert into student values
(108,'赵红','女',to_date('1985-02-10','YYYY-MM-DD'),'95034');
insert into student values
(109,'张伟','男',to_date('1984-06-03','YYYY-MM-DD'),'95035');
insert into teacher values
(804,'李诚','男',to_date('1968-12-02','YYYY-MM-DD'),'副教授','计算机系');
insert into teacher values
(856,'张旭','男',to_date('1975-09-02','YYYY-MM-DD'),'讲师','电子工程系');
insert into teacher values
(825,'王萍','女',to_date('1978-05-08','YYYY-MM-DD'),'助教','计算机系');
insert into teacher values
(831,'刘冰','女',to_date('1979-08-10','YYYY-MM-DD'),'助教','电子工程系');
insert into course values
('3-105','计算机导论',825);
insert into course values
('3-245','操作系统',804);
insert into course values
('6-166','数字电路',856);
insert into course values
('9-888','高等数学',831);
insert into score values(103,'3-245',86);
insert into score values(105,'3-245',75);
insert into score values(109,'3-245',68);
insert into score values(103,'3-105',92);
insert into score values(105,'3-105',88);
insert into score values(109,'3-105',76);
insert into score values(101,'3-105',64);
insert into score values(107,'3-105',91);
insert into score values(108,'3-105',78);
insert into score values(101,'6-166',85);
insert into score values(107,'6-166',79);
insert into score values(108,'6-166',81);
以下是所有Java源代码,一共将近20个.java文件。
//Login.java
package XSCJ;
import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.JFrame;
import javax.swing.UIManager;
public class Login {
public Login() {
JFrame frame = new Frame1();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = frame.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
frame.setLocation((screenSize.width - frameSize.width) / 2,
(screenSize.height - frameSize.height) / 2);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
e.printStackTrace();
}
new Login();
}
}
package XSCJ;
import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.JFrame;
import javax.swing.UIManager;
public class Login {
public Login() {
JFrame frame = new Frame1();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = frame.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
frame.setLocation((screenSize.width - frameSize.width) / 2,
(screenSize.height - frameSize.height) / 2);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
e.printStackTrace();
}
new Login();
}
}
//Frame1.java
package XSCJ;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import java.sql.*;
import javax.swing.JRadioButton;
public class Frame1 extends JFrame {
Vector v = new Vector();
char str[] = new char[20];
String username = new String();
String password = new String();
private JMenuBar menuBar = new JMenuBar();
private JMenu menuFile = new JMenu();
private JMenuItem menuFileExit = new JMenuItem();
private JMenu menuHelp = new JMenu();
private JMenuItem menuHelpAbout = new JMenuItem();
private JLabel textWelcome = new JLabel();
private JLabel textUserName = new JLabel();
private JLabel textPassword = new JLabel();
private JPasswordField inputPassword = new JPasswordField();
private JComboBox chooseUser = new JComboBox(v);
private JButton loginIn = new JButton();
private JLabel jLabel2 = new JLabel();
public Frame1() {
try {
jbInit();
} catch (Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
Connection conn = null;
Statement state = null;
try {
Class.forName("oracle.jdbc.OracleDriver").newInstance();
conn =
DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XSCJ", "system",
"qazwsx");
state = conn.createStatement();
ResultSet rs = state.executeQuery("select userID from users");
while (rs.next())
v.addElement(rs.getString("userID"));
rs.close();
} catch (SQLException e) {
System.out.println("Error Code=" + e.getErrorCode());
System.out.println("Error Message=" + e.getMessage());
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (state != null) {
state.close();
}
if (conn != null) {
conn.close();
}
} catch (SQLException e) {
System.out.println("Error Code=" + e.getErrorCode());
System.out.println("Error Message=" + e.getMessage());
}
}
this.setTitle("学生成绩管理系统");
this.setJMenuBar(menuBar);
this.getContentPane().setLayout(null);
this.setSize(new Dimension(400, 300));
menuFile.setText("File");
menuFileExit.setText("Exit");
menuFileExit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
fileExit_ActionPerformed(ae);
}
});
menuHelp.setText("Help");
menuHelpAbout.setText("About");
menuHelpAbout.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
helpAbout_ActionPerformed(ae);
}
});
textWelcome.setText("欢迎使用学生成绩管理系统");
textWelcome.setBounds(new Rectangle(120, 30, 150, 40));
textUserName.setText("用户名:");
textUserName.setBounds(new Rectangle(60, 80, 60, 25));
textPassword.setText("密 码:");
textPassword.setBounds(new Rectangle(60, 105, 60, 25));
inputPassword.setBounds(new Rectangle(120, 105, 95, 25));
chooseUser.setBounds(new Rectangle(120, 80, 95, 25));
chooseUser.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
chooseUser_actionPerformed(e);
}
});
loginIn.setText("登 陆");
loginIn.setBounds(new Rectangle(250, 100, 95, 30));
loginIn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
loginIn_actionPerformed(e);
}
});
jLabel2.setText("严禁未经授权使用此系统, 否则可能会面临民事和刑事起诉。");
jLabel2.setBounds(new Rectangle(45, 195, 325, 25));
menuFile.add(menuFileExit);
menuBar.add(menuFile);
menuHelp.add(menuHelpAbout);
menuBar.add(menuHelp);
this.getContentPane().add(jLabel2, null);
this.getContentPane().add(loginIn, null);
this.getContentPane().add(chooseUser, null);
this.getContentPane().add(inputPassword, null);
this.getContentPane().add(textPassword, null);
this.getContentPane().add(textUserName, null);
this.getContentPane().add(textWelcome, null);
}
void fileExit_ActionPerformed(ActionEvent e) {
System.exit(0);
}
void helpAbout_ActionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(this, new Frame1_AboutBoxPanel1(),
"About", JOptionPane.PLAIN_MESSAGE);
}
void chooseUser_actionPerformed(ActionEvent e) {
username = (String)chooseUser.getSelectedItem();
}
private void loginIn_actionPerformed(ActionEvent e) {
char[] str = inputPassword.getPassword();
password = new String(str);
while (password.length() < 20)
password += " ";
Connection conn = null;
Statement state = null;
ResultSet rs;
String password_get = new String("");
int quanxian_get = 1;
try {
Class.forName("oracle.jdbc.OracleDriver").newInstance();
conn =
DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XSCJ", "system",
"qazwsx");
state = conn.createStatement();
rs =
state.executeQuery("select password,quanxian from users where userID='" +
username + "'");
rs.next();
password_get = rs.getString("password");
quanxian_get = rs.getInt("quanxian");
} catch (SQLException e1) {
System.out.println("Error Code=" + e1.getErrorCode());
System.out.println("Error Message=" + e1.getMessage());
} catch (Exception e1) {
e1.printStackTrace();
} finally {
try {
if (state != null) {
state.close();
}
if (conn != null) {
conn.close();
}
} catch (SQLException e1) {
System.out.println("Error Code=" + e1.getErrorCode());
System.out.println("Error Message=" + e1.getMessage());
}
}
if (password_get.equals(password) == false) {
System.exit(0);
} else if (quanxian_get > 1) {
this.dispose();
new mainWindowAdmin().setVisible(true);
} else {
this.dispose();
new mainWindowNormal().setVisible(true);
}
}
}
package XSCJ;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import java.sql.*;
import javax.swing.JRadioButton;
public class Frame1 extends JFrame {
Vector v = new Vector();
char str[] = new char[20];
String username = new String();
String password = new String();
private JMenuBar menuBar = new JMenuBar();
private JMenu menuFile = new JMenu();
private JMenuItem menuFileExit = new JMenuItem();
private JMenu menuHelp = new JMenu();
private JMenuItem menuHelpAbout = new JMenuItem();
private JLabel textWelcome = new JLabel();
private JLabel textUserName = new JLabel();
private JLabel textPassword = new JLabel();
private JPasswordField inputPassword = new JPasswordField();
private JComboBox chooseUser = new JComboBox(v);
private JButton loginIn = new JButton();
private JLabel jLabel2 = new JLabel();
public Frame1() {
try {
jbInit();
} catch (Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
Connection conn = null;
Statement state = null;
try {
Class.forName("oracle.jdbc.OracleDriver").newInstance();
conn =
DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XSCJ", "system",
"qazwsx");
state = conn.createStatement();
ResultSet rs = state.executeQuery("select userID from users");
while (rs.next())
v.addElement(rs.getString("userID"));
rs.close();
} catch (SQLException e) {
System.out.println("Error Code=" + e.getErrorCode());
System.out.println("Error Message=" + e.getMessage());
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (state != null) {
state.close();
}
if (conn != null) {
conn.close();
}
} catch (SQLException e) {
System.out.println("Error Code=" + e.getErrorCode());
System.out.println("Error Message=" + e.getMessage());
}
}
this.setTitle("学生成绩管理系统");
this.setJMenuBar(menuBar);
this.getContentPane().setLayout(null);
this.setSize(new Dimension(400, 300));
menuFile.setText("File");
menuFileExit.setText("Exit");
menuFileExit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
fileExit_ActionPerformed(ae);
}
});
menuHelp.setText("Help");
menuHelpAbout.setText("About");
menuHelpAbout.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
helpAbout_ActionPerformed(ae);
}
});
textWelcome.setText("欢迎使用学生成绩管理系统");
textWelcome.setBounds(new Rectangle(120, 30, 150, 40));
textUserName.setText("用户名:");
textUserName.setBounds(new Rectangle(60, 80, 60, 25));
textPassword.setText("密 码:");
textPassword.setBounds(new Rectangle(60, 105, 60, 25));
inputPassword.setBounds(new Rectangle(120, 105, 95, 25));
chooseUser.setBounds(new Rectangle(120, 80, 95, 25));
chooseUser.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
chooseUser_actionPerformed(e);
}
});
loginIn.setText("登 陆");
loginIn.setBounds(new Rectangle(250, 100, 95, 30));
loginIn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
loginIn_actionPerformed(e);
}
});
jLabel2.setText("严禁未经授权使用此系统, 否则可能会面临民事和刑事起诉。");
jLabel2.setBounds(new Rectangle(45, 195, 325, 25));
menuFile.add(menuFileExit);
menuBar.add(menuFile);
menuHelp.add(menuHelpAbout);
menuBar.add(menuHelp);
this.getContentPane().add(jLabel2, null);
this.getContentPane().add(loginIn, null);
this.getContentPane().add(chooseUser, null);
this.getContentPane().add(inputPassword, null);
this.getContentPane().add(textPassword, null);
this.getContentPane().add(textUserName, null);
this.getContentPane().add(textWelcome, null);
}
void fileExit_ActionPerformed(ActionEvent e) {
System.exit(0);
}
void helpAbout_ActionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(this, new Frame1_AboutBoxPanel1(),
"About", JOptionPane.PLAIN_MESSAGE);
}
void chooseUser_actionPerformed(ActionEvent e) {
username = (String)chooseUser.getSelectedItem();
}
private void loginIn_actionPerformed(ActionEvent e) {
char[] str = inputPassword.getPassword();
password = new String(str);
while (password.length() < 20)
password += " ";
Connection conn = null;
Statement state = null;
ResultSet rs;
String password_get = new String("");
int quanxian_get = 1;
try {
Class.forName("oracle.jdbc.OracleDriver").newInstance();
conn =
DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XSCJ", "system",
"qazwsx");
state = conn.createStatement();
rs =
state.executeQuery("select password,quanxian from users where userID='" +
username + "'");
rs.next();
password_get = rs.getString("password");
quanxian_get = rs.getInt("quanxian");
} catch (SQLException e1) {
System.out.println("Error Code=" + e1.getErrorCode());
System.out.println("Error Message=" + e1.getMessage());
} catch (Exception e1) {
e1.printStackTrace();
} finally {
try {
if (state != null) {
state.close();
}
if (conn != null) {
conn.close();
}
} catch (SQLException e1) {
System.out.println("Error Code=" + e1.getErrorCode());
System.out.println("Error Message=" + e1.getMessage());
}
}
if (password_get.equals(password) == false) {
System.exit(0);
} else if (quanxian_get > 1) {
this.dispose();
new mainWindowAdmin().setVisible(true);
} else {
this.dispose();
new mainWindowNormal().setVisible(true);
}
}
}
//Frame1_AboutBoxPanel1.java
package XSCJ;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.Border;
public class Frame1_AboutBoxPanel1 extends JPanel {
private JLabel labelTitle = new JLabel();
private JLabel labelAuthor = new JLabel();
private JLabel labelStudentNumber = new JLabel();
private JLabel labelEmail = new JLabel();
private JLabel labelCompany = new JLabel();
private GridBagLayout layoutMain = new GridBagLayout();
private Border border = BorderFactory.createEtchedBorder();
public Frame1_AboutBoxPanel1() {
try {
jbInit();
} catch (Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
this.setLayout(layoutMain);
this.setBorder(border);
labelTitle.setText(" 学生成绩管理系统 V0.5");
labelAuthor.setText(" Derek");
labelStudentNumber.setText(" ");
labelEmail.setText("@hotmail.com");
labelCompany.setText(" ");
this.add(labelTitle,
new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST,
GridBagConstraints.NONE,
new Insets(5, 15, 0, 15), 0, 0));
this.add(labelAuthor,
new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST,
GridBagConstraints.NONE,
new Insets(0, 15, 0, 15), 0, 0));
this.add(labelStudentNumber,
new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0,
GridBagConstraints.WEST,
GridBagConstraints.NONE,
new Insets(0, 15, 0, 15), 0, 0));
this.add(labelEmail,
new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.WEST,
GridBagConstraints.NONE,
new Insets(0, 15, 0, 15), 0, 0));
this.add(labelCompany,
new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.WEST,
GridBagConstraints.NONE,
new Insets(0, 15, 5, 15), 0, 0));
}
}
package XSCJ;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.Border;
public class Frame1_AboutBoxPanel1 extends JPanel {
private JLabel labelTitle = new JLabel();
private JLabel labelAuthor = new JLabel();
private JLabel labelStudentNumber = new JLabel();
private JLabel labelEmail = new JLabel();
private JLabel labelCompany = new JLabel();
private GridBagLayout layoutMain = new GridBagLayout();
private Border border = BorderFactory.createEtchedBorder();
public Frame1_AboutBoxPanel1() {
try {
jbInit();
} catch (Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
this.setLayout(layoutMain);
this.setBorder(border);
labelTitle.setText(" 学生成绩管理系统 V0.5");
labelAuthor.setText(" Derek");
labelStudentNumber.setText(" ");
labelEmail.setText("@hotmail.com");
labelCompany.setText(" ");
this.add(labelTitle,
new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST,
GridBagConstraints.NONE,
new Insets(5, 15, 0, 15), 0, 0));
this.add(labelAuthor,
new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST,
GridBagConstraints.NONE,
new Insets(0, 15, 0, 15), 0, 0));
this.add(labelStudentNumber,
new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0,
GridBagConstraints.WEST,
GridBagConstraints.NONE,
new Insets(0, 15, 0, 15), 0, 0));
this.add(labelEmail,
new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.WEST,
GridBagConstraints.NONE,
new Insets(0, 15, 0, 15), 0, 0));
this.add(labelCompany,
new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.WEST,
GridBagConstraints.NONE,
new Insets(0, 15, 5, 15), 0, 0));
}
}
//mainWindowAdmin.java
package XSCJ;
import java.awt.Dimension;
import java.awt.Rectangle;
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;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class mainWindowAdmin extends JFrame {
String operation;
String table;
//v1.addElement("查询、更新、删除");
String[] choose_operation = { "查询、修改、删除", "插入" };
String[] choose_table = { "学生信息", "教师信息", "课程信息", "成绩信息" };
String[] s={"选课情况","教学情况"};
private JLabel jLabel1 = new JLabel();
private JLabel jLabel2 = new JLabel();
private JLabel jLabel3 = new JLabel();
private JLabel jLabel4 = new JLabel();
private JButton jButton1 = new JButton();
private JButton jButton2 = new JButton();
private JButton jButton3 = new JButton();
private JButton jButton4 = new JButton();
private JButton jButton5 = new JButton();
JComboBox chooseOperation = new JComboBox(choose_operation);
JComboBox chooseTable = new JComboBox(choose_table);
private JLabel jLabel5 = new JLabel();
private JComboBox findInformation = new JComboBox(s);
private JLabel jLabel6 = new JLabel();
private JButton jButton6 = new JButton();
public mainWindowAdmin() {
try {
jbInit();
} catch (Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
this.getContentPane().setLayout(null);
this.setSize(new Dimension(443, 388));
this.setTitle("欢迎使用学生成绩管理系统 V0.5");
jLabel1.setText("请选择操作:");
jLabel1.setBounds(new Rectangle(50, 195, 90, 20));
jLabel2.setText("请选择数据表:");
jLabel2.setBounds(new Rectangle(50, 220, 90, 20));
jLabel3.setText("修改数据:");
jLabel3.setBounds(new Rectangle(30, 170, 160, 20));
jLabel4.setText("查看数据:");
jLabel4.setBounds(new Rectangle(30, 30, 115, 25));
jButton1.setText("学生信息");
jButton1.setBounds(new Rectangle(105, 65, 80, 35));
jButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton1_actionPerformed(e);
}
});
jButton2.setText("教师信息");
jButton2.setBounds(new Rectangle(210, 65, 80, 35));
jButton2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton2_actionPerformed(e);
}
});
jButton3.setText("课程信息");
jButton3.setBounds(new Rectangle(105, 115, 80, 35));
jButton3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton3_actionPerformed(e);
}
});
jButton4.setText("成绩信息");
jButton4.setBounds(new Rectangle(210, 115, 80, 35));
jButton4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton4_actionPerformed(e);
}
});
jButton5.setText("GO");
jButton5.setBounds(new Rectangle(300, 220, 75, 20));
jButton5.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton5_actionPerformed(e);
}
});
chooseOperation.setBounds(new Rectangle(140, 195, 130, 20));
chooseTable.setBounds(new Rectangle(140, 220, 130, 20));
jLabel5.setText("高级查询:");
jLabel5.setBounds(new Rectangle(50, 290, 90, 20));
findInformation.setBounds(new Rectangle(140, 290, 130, 20));
jLabel6.setText("附加功能:");
jLabel6.setBounds(new Rectangle(30, 270, 110, 15));
jButton6.setText("GO");
jButton6.setBounds(new Rectangle(300, 290, 80, 20));
jButton6.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton6_actionPerformed(e);
}
});
this.getContentPane().add(jButton6, null);
this.getContentPane().add(jLabel6, null);
this.getContentPane().add(findInformation, null);
this.getContentPane().add(jLabel5, null);
this.getContentPane().add(chooseTable, null);
this.getContentPane().add(chooseOperation, null);
this.getContentPane().add(jButton5, null);
this.getContentPane().add(jButton4, null);
this.getContentPane().add(jButton3, null);
this.getContentPane().add(jButton2, null);
this.getContentPane().add(jButton1, null);
this.getContentPane().add(jLabel4, null);
this.getContentPane().add(jLabel3, null);
this.getContentPane().add(jLabel2, null);
this.getContentPane().add(jLabel1, null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
void jButton1_actionPerformed(ActionEvent e) {
new studentInformation().setVisible(true);
}
void jButton2_actionPerformed(ActionEvent e) {
new teacherInformation().setVisible(true);
}
void jButton3_actionPerformed(ActionEvent e) {
new courseInformation().setVisible(true);
}
void jButton4_actionPerformed(ActionEvent e) {
new scoreInformation().setVisible(true);
}
private void jButton5_actionPerformed(ActionEvent e) {
operation = (String)chooseOperation.getSelectedItem();
table = (String)chooseTable.getSelectedItem();
if (operation.equals("查询、修改、删除")) {
if (table.equals("学生信息"))
new studentUpdate().setVisible(true);
else if (table.equals("教师信息"))
new teacherUpdate().setVisible(true);
else if (table.equals("课程信息"))
new courseUpdate().setVisible(true);
else
new scoreUpdate().setVisible(true);
} else {
if (table.equals("学生信息"))
new insertStudent().setVisible(true);
else if (table.equals("教师信息"))
new insertTeacher().setVisible(true);
else if (table.equals("课程信息"))
new insertCourse().setVisible(true);
else
new insertScore().setVisible(true);
}
}
private void jButton6_actionPerformed(ActionEvent e) {
String information=(String)findInformation.getSelectedItem();
if(information.equals("选课情况"))
new select1().setVisible(true);
else
new select2().setVisible(true);
}
}
package XSCJ;
import java.awt.Dimension;
import java.awt.Rectangle;
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;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class mainWindowAdmin extends JFrame {
String operation;
String table;
//v1.addElement("查询、更新、删除");
String[] choose_operation = { "查询、修改、删除", "插入" };
String[] choose_table = { "学生信息", "教师信息", "课程信息", "成绩信息" };
String[] s={"选课情况","教学情况"};
private JLabel jLabel1 = new JLabel();
private JLabel jLabel2 = new JLabel();
private JLabel jLabel3 = new JLabel();
private JLabel jLabel4 = new JLabel();
private JButton jButton1 = new JButton();
private JButton jButton2 = new JButton();
private JButton jButton3 = new JButton();
private JButton jButton4 = new JButton();
private JButton jButton5 = new JButton();
JComboBox chooseOperation = new JComboBox(choose_operation);
JComboBox chooseTable = new JComboBox(choose_table);
private JLabel jLabel5 = new JLabel();
private JComboBox findInformation = new JComboBox(s);
private JLabel jLabel6 = new JLabel();
private JButton jButton6 = new JButton();
public mainWindowAdmin() {
try {
jbInit();
} catch (Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
this.getContentPane().setLayout(null);
this.setSize(new Dimension(443, 388));
this.setTitle("欢迎使用学生成绩管理系统 V0.5");
jLabel1.setText("请选择操作:");
jLabel1.setBounds(new Rectangle(50, 195, 90, 20));
jLabel2.setText("请选择数据表:");
jLabel2.setBounds(new Rectangle(50, 220, 90, 20));
jLabel3.setText("修改数据:");
jLabel3.setBounds(new Rectangle(30, 170, 160, 20));
jLabel4.setText("查看数据:");
jLabel4.setBounds(new Rectangle(30, 30, 115, 25));
jButton1.setText("学生信息");
jButton1.setBounds(new Rectangle(105, 65, 80, 35));
jButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton1_actionPerformed(e);
}
});
jButton2.setText("教师信息");
jButton2.setBounds(new Rectangle(210, 65, 80, 35));
jButton2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton2_actionPerformed(e);
}
});
jButton3.setText("课程信息");
jButton3.setBounds(new Rectangle(105, 115, 80, 35));
jButton3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton3_actionPerformed(e);
}
});
jButton4.setText("成绩信息");
jButton4.setBounds(new Rectangle(210, 115, 80, 35));
jButton4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton4_actionPerformed(e);
}
});
jButton5.setText("GO");
jButton5.setBounds(new Rectangle(300, 220, 75, 20));
jButton5.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton5_actionPerformed(e);
}
});
chooseOperation.setBounds(new Rectangle(140, 195, 130, 20));
chooseTable.setBounds(new Rectangle(140, 220, 130, 20));
jLabel5.setText("高级查询:");
jLabel5.setBounds(new Rectangle(50, 290, 90, 20));
findInformation.setBounds(new Rectangle(140, 290, 130, 20));
jLabel6.setText("附加功能:");
jLabel6.setBounds(new Rectangle(30, 270, 110, 15));
jButton6.setText("GO");
jButton6.setBounds(new Rectangle(300, 290, 80, 20));
jButton6.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton6_actionPerformed(e);
}
});
this.getContentPane().add(jButton6, null);
this.getContentPane().add(jLabel6, null);
this.getContentPane().add(findInformation, null);
this.getContentPane().add(jLabel5, null);
this.getContentPane().add(chooseTable, null);
this.getContentPane().add(chooseOperation, null);
this.getContentPane().add(jButton5, null);
this.getContentPane().add(jButton4, null);
this.getContentPane().add(jButton3, null);
this.getContentPane().add(jButton2, null);
this.getContentPane().add(jButton1, null);
this.getContentPane().add(jLabel4, null);
this.getContentPane().add(jLabel3, null);
this.getContentPane().add(jLabel2, null);
this.getContentPane().add(jLabel1, null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
void jButton1_actionPerformed(ActionEvent e) {
new studentInformation().setVisible(true);
}
void jButton2_actionPerformed(ActionEvent e) {
new teacherInformation().setVisible(true);
}
void jButton3_actionPerformed(ActionEvent e) {
new courseInformation().setVisible(true);
}
void jButton4_actionPerformed(ActionEvent e) {
new scoreInformation().setVisible(true);
}
private void jButton5_actionPerformed(ActionEvent e) {
operation = (String)chooseOperation.getSelectedItem();
table = (String)chooseTable.getSelectedItem();
if (operation.equals("查询、修改、删除")) {
if (table.equals("学生信息"))
new studentUpdate().setVisible(true);
else if (table.equals("教师信息"))
new teacherUpdate().setVisible(true);
else if (table.equals("课程信息"))
new courseUpdate().setVisible(true);
else
new scoreUpdate().setVisible(true);
} else {
if (table.equals("学生信息"))
new insertStudent().setVisible(true);
else if (table.equals("教师信息"))
new insertTeacher().setVisible(true);
else if (table.equals("课程信息"))
new insertCourse().setVisible(true);
else
new insertScore().setVisible(true);
}
}
private void jButton6_actionPerformed(ActionEvent e) {
String information=(String)findInformation.getSelectedItem();
if(information.equals("选课情况"))
new select1().setVisible(true);
else
new select2().setVisible(true);
}
}
//mainWindowNormal.java
package XSCJ;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class mainWindowNormal extends JFrame {
private JButton student = new JButton();
private JButton teacher = new JButton();
private JButton course = new JButton();
private JButton score = new JButton();
private JLabel welcome = new JLabel();
private JLabel explain = new JLabel();
public mainWindowNormal() {
try {
jbInit();
} catch (Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
this.getContentPane().setLayout(null);
this.setSize(new Dimension(400, 300));
this.setTitle("欢迎使用学生成绩管理系统 V0.5");
student.setText("学生信息");
student.setBounds(new Rectangle(70, 105, 105, 35));
student.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
student_actionPerformed(e);
}
});
teacher.setText("教师信息");
teacher.setBounds(new Rectangle(195, 105, 105, 35));
teacher.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
teacher_actionPerformed(e);
}
});
course.setText("课程信息");
course.setBounds(new Rectangle(70, 160, 105, 35));
course.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
course_actionPerformed(e);
}
});
score.setText("成绩信息");
score.setBounds(new Rectangle(195, 160, 105, 35));
score.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
score_actionPerformed(e);
}
});
welcome.setText("欢迎使用学生成绩管理系统");
welcome.setBounds(new Rectangle(110, 60, 150, 35));
explain.setText("普通用户仅具有查看表数据权限");
explain.setBounds(new Rectangle(100, 215, 185, 25));
this.getContentPane().add(explain, null);
this.getContentPane().add(welcome, null);
this.getContentPane().add(score, null);
this.getContentPane().add(course, null);
this.getContentPane().add(teacher, null);
this.getContentPane().add(student, null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
private void student_actionPerformed(ActionEvent e) {
new studentInformation().setVisible(true);
}
private void teacher_actionPerformed(ActionEvent e) {
new teacherInformation().setVisible(true);
}
private void course_actionPerformed(ActionEvent e) {
new courseInformation().setVisible(true);
}
private void score_actionPerformed(ActionEvent e) {
new scoreInformation().setVisible(true);
}
}
package XSCJ;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class mainWindowNormal extends JFrame {
private JButton student = new JButton();
private JButton teacher = new JButton();
private JButton course = new JButton();
private JButton score = new JButton();
private JLabel welcome = new JLabel();
private JLabel explain = new JLabel();
public mainWindowNormal() {
try {
jbInit();
} catch (Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
this.getContentPane().setLayout(null);
this.setSize(new Dimension(400, 300));
this.setTitle("欢迎使用学生成绩管理系统 V0.5");
student.setText("学生信息");
student.setBounds(new Rectangle(70, 105, 105, 35));
student.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
student_actionPerformed(e);
}
});
teacher.setText("教师信息");
teacher.setBounds(new Rectangle(195, 105, 105, 35));
teacher.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
teacher_actionPerformed(e);
}
});
course.setText("课程信息");
course.setBounds(new Rectangle(70, 160, 105, 35));
course.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
course_actionPerformed(e);
}
});
score.setText("成绩信息");
score.setBounds(new Rectangle(195, 160, 105, 35));
score.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
score_actionPerformed(e);
}
});
welcome.setText("欢迎使用学生成绩管理系统");
welcome.setBounds(new Rectangle(110, 60, 150, 35));
explain.setText("普通用户仅具有查看表数据权限");
explain.setBounds(new Rectangle(100, 215, 185, 25));
this.getContentPane().add(explain, null);
this.getContentPane().add(welcome, null);
this.getContentPane().add(score, null);
this.getContentPane().add(course, null);
this.getContentPane().add(teacher, null);
this.getContentPane().add(student, null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
private void student_actionPerformed(ActionEvent e) {
new studentInformation().setVisible(true);
}
private void teacher_actionPerformed(ActionEvent e) {
new teacherInformation().setVisible(true);
}
private void course_actionPerformed(ActionEvent e) {
new courseInformation().setVisible(true);
}
private void score_actionPerformed(ActionEvent e) {
new scoreInformation().setVisible(true);
}
}
//studentInformation.java
package XSCJ;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.util.Vector;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.RowSorter;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableRowSorter;
public class studentInformation extends JFrame {
String[] column = { "学号", "学生姓名", "学生性别", "出生日期", "班级" };
private JMenuBar menuBar = new JMenuBar();
private JMenu menuFile = new JMenu();
private JMenuItem menuFileExit = new JMenuItem();
private JTable studentTable = new JTable();
DefaultTableModel mm = new DefaultTableModel(column, 0) {
};
public studentInformation() {
try {
jbInit();
} catch (Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
this.setJMenuBar(menuBar);
this.getContentPane().setLayout(null);
this.setSize(new Dimension(491, 391));
this.setTitle("学生信息");
menuFile.setText("File");
menuFileExit.setText("Exit");
menuFileExit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
fileExit_ActionPerformed(ae);
}
});
studentTable.setBounds(new Rectangle(25, 25, 435, 290));
menuFile.add(menuFileExit);
menuBar.add(menuFile);
this.getContentPane().add(studentTable, null);
int studentNumber;
String studentName, studentSex, studentClass;
Date studentBirthday;
Connection conn = null;
Statement state = null;
try {
Class.forName("oracle.jdbc.OracleDriver").newInstance();
conn =
DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XSCJ", "system",
"qazwsx");
state = conn.createStatement();
ResultSet rs = state.executeQuery("select * from student");
while (rs.next()) {
studentNumber = rs.getInt("sno");
studentName = rs.getString("name");
studentSex = rs.getString("sex");
studentBirthday = rs.getDate("birthday");
studentClass = rs.getString("class");
Object[] studentInfo =
{ studentNumber, studentName, studentSex, studentBirthday,
studentClass };
mm.addRow(studentInfo);
}
studentTable.setModel(mm);
rs.close();
} catch (SQLException e) {
System.out.println("Error Code=" + e.getErrorCode());
System.out.println("Error Message=" + e.getMessage());
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (state != null) {
state.close();
}
if (conn != null) {
conn.close();
}
} catch (SQLException e) {
System.out.println("Error Code=" + e.getErrorCode());
System.out.println("Error Message=" + e.getMessage());
}
}
}
void fileExit_ActionPerformed(ActionEvent e) {
System.exit(0);
}
}
package XSCJ;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.util.Vector;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.RowSorter;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableRowSorter;
public class studentInformation extends JFrame {
String[] column = { "学号", "学生姓名", "学生性别", "出生日期", "班级" };
private JMenuBar menuBar = new JMenuBar();
private JMenu menuFile = new JMenu();
private JMenuItem menuFileExit = new JMenuItem();
private JTable studentTable = new JTable();
DefaultTableModel mm = new DefaultTableModel(column, 0) {
};
public studentInformation() {
try {
jbInit();
} catch (Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
this.setJMenuBar(menuBar);
this.getContentPane().setLayout(null);
this.setSize(new Dimension(491, 391));
this.setTitle("学生信息");
menuFile.setText("File");
menuFileExit.setText("Exit");
menuFileExit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
fileExit_ActionPerformed(ae);
}
});
studentTable.setBounds(new Rectangle(25, 25, 435, 290));
menuFile.add(menuFileExit);
menuBar.add(menuFile);
this.getContentPane().add(studentTable, null);
int studentNumber;
String studentName, studentSex, studentClass;
Date studentBirthday;
Connection conn = null;
Statement state = null;
try {
Class.forName("oracle.jdbc.OracleDriver").newInstance();
conn =
DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XSCJ", "system",
"qazwsx");
state = conn.createStatement();
ResultSet rs = state.executeQuery("select * from student");
while (rs.next()) {
studentNumber = rs.getInt("sno");
studentName = rs.getString("name");
studentSex = rs.getString("sex");
studentBirthday = rs.getDate("birthday");
studentClass = rs.getString("class");
Object[] studentInfo =
{ studentNumber, studentName, studentSex, studentBirthday,
studentClass };
mm.addRow(studentInfo);
}
studentTable.setModel(mm);
rs.close();
} catch (SQLException e) {
System.out.println("Error Code=" + e.getErrorCode());
System.out.println("Error Message=" + e.getMessage());
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (state != null) {
state.close();
}
if (conn != null) {
conn.close();
}
} catch (SQLException e) {
System.out.println("Error Code=" + e.getErrorCode());
System.out.println("Error Message=" + e.getMessage());
}
}
}
void fileExit_ActionPerformed(ActionEvent e) {
System.exit(0);
}
}
//teacherInformation.java
package XSCJ;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
public class teacherInformation extends JFrame {
String[] column = { "教师号", "教师姓名", "性别", "出生日期", "职称", "院系" };
private JMenuBar menuBar = new JMenuBar();
private JMenu menuFile = new JMenu();
private JMenuItem menuFileExit = new JMenuItem();
private JTable teacherTable = new JTable();
DefaultTableModel mm = new DefaultTableModel(column, 0) {
};
public teacherInformation() {
try {
jbInit();
} catch (Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
this.setJMenuBar(menuBar);
this.getContentPane().setLayout(null);
this.setSize(new Dimension(534, 435));
this.setTitle("教师信息");
menuFile.setText("File");
menuFileExit.setText("Exit");
menuFileExit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
fileExit_ActionPerformed(ae);
}
});
teacherTable.setBounds(new Rectangle(20, 25, 490, 290));
menuFile.add(menuFileExit);
menuBar.add(menuFile);
this.getContentPane().add(teacherTable, null);
int teacherNumber;
String teacherName, teacherSex, teacherProf, teacherDepart;
Date teacherBirthday;
Connection conn = null;
Statement state = null;
try {
Class.forName("oracle.jdbc.OracleDriver").newInstance();
conn =
DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XSCJ", "system",
"qazwsx");
state = conn.createStatement();
ResultSet rs = state.executeQuery("select * from teacher");
while (rs.next()) {
teacherNumber = rs.getInt("tno");
teacherName = rs.getString("name");
teacherSex = rs.getString("sex");
teacherBirthday = rs.getDate("birthday");
teacherProf = rs.getString("prof");
teacherDepart = rs.getString("depart");
Object[] teacherInfo =
{ teacherNumber, teacherName, teacherSex, teacherBirthday,
teacherProf, teacherDepart };
mm.addRow(teacherInfo);
}
teacherTable.setModel(mm);
rs.close();
} catch (SQLException e) {
System.out.println("Error Code=" + e.getErrorCode());
System.out.println("Error Message=" + e.getMessage());
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (state != null) {
state.close();
}
if (conn != null) {
conn.close();
}
} catch (SQLException e) {
System.out.println("Error Code=" + e.getErrorCode());
System.out.println("Error Message=" + e.getMessage());
}
}
}
void fileExit_ActionPerformed(ActionEvent e) {
System.exit(0);
}
}
package XSCJ;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
public class teacherInformation extends JFrame {
String[] column = { "教师号", "教师姓名", "性别", "出生日期", "职称", "院系" };
private JMenuBar menuBar = new JMenuBar();
private JMenu menuFile = new JMenu();
private JMenuItem menuFileExit = new JMenuItem();
private JTable teacherTable = new JTable();
DefaultTableModel mm = new DefaultTableModel(column, 0) {
};
public teacherInformation() {
try {
jbInit();
} catch (Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
this.setJMenuBar(menuBar);
this.getContentPane().setLayout(null);
this.setSize(new Dimension(534, 435));
this.setTitle("教师信息");
menuFile.setText("File");
menuFileExit.setText("Exit");
menuFileExit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
fileExit_ActionPerformed(ae);
}
});
teacherTable.setBounds(new Rectangle(20, 25, 490, 290));
menuFile.add(menuFileExit);
menuBar.add(menuFile);
this.getContentPane().add(teacherTable, null);
int teacherNumber;
String teacherName, teacherSex, teacherProf, teacherDepart;
Date teacherBirthday;
Connection conn = null;
Statement state = null;
try {
Class.forName("oracle.jdbc.OracleDriver").newInstance();
conn =
DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XSCJ", "system",
"qazwsx");
state = conn.createStatement();
ResultSet rs = state.executeQuery("select * from teacher");
while (rs.next()) {
teacherNumber = rs.getInt("tno");
teacherName = rs.getString("name");
teacherSex = rs.getString("sex");
teacherBirthday = rs.getDate("birthday");
teacherProf = rs.getString("prof");
teacherDepart = rs.getString("depart");
Object[] teacherInfo =
{ teacherNumber, teacherName, teacherSex, teacherBirthday,
teacherProf, teacherDepart };
mm.addRow(teacherInfo);
}
teacherTable.setModel(mm);
rs.close();
} catch (SQLException e) {
System.out.println("Error Code=" + e.getErrorCode());
System.out.println("Error Message=" + e.getMessage());
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (state != null) {
state.close();
}
if (conn != null) {
conn.close();
}
} catch (SQLException e) {
System.out.println("Error Code=" + e.getErrorCode());
System.out.println("Error Message=" + e.getMessage());
}
}
}
void fileExit_ActionPerformed(ActionEvent e) {
System.exit(0);
}
}
//courseInformation.java
package XSCJ;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
public class courseInformation extends JFrame {
String[] column = { "课程号", "课程名称", "学生姓名" };
private JMenuBar menuBar = new JMenuBar();
private JMenu menuFile = new JMenu();
private JMenuItem menuFileExit = new JMenuItem();
private JTable courseTable = new JTable();
DefaultTableModel mm = new DefaultTableModel(column, 0) {
};
public courseInformation() {
try {
jbInit();
} catch (Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
this.setJMenuBar(menuBar);
this.getContentPane().setLayout(null);
this.setSize(new Dimension(489, 383));
this.setTitle("课程信息");
menuFile.setText("File");
menuFileExit.setText("Exit");
menuFileExit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
fileExit_ActionPerformed(ae);
}
});
courseTable.setBounds(new Rectangle(17, 35, 450, 260));
menuFile.add(menuFileExit);
menuBar.add(menuFile);
this.getContentPane().add(courseTable, null);
String courseNumber, courseName, teacherName;
Connection conn = null;
Statement state = null;
try {
Class.forName("oracle.jdbc.OracleDriver").newInstance();
conn =
DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XSCJ", "system",
"qazwsx");
state = conn.createStatement();
ResultSet rs =
state.executeQuery("select cno,cname,teacher.name from course,teacher where course.tno=teacher.tno");
while (rs.next()) {
courseNumber = rs.getString("cno");
courseName = rs.getString("cname");
teacherName = rs.getString("name");
Object[] courseInfo =
{ courseNumber, courseName, teacherName };
mm.addRow(courseInfo);
}
courseTable.setModel(mm);
rs.close();
} catch (SQLException e) {
System.out.println("Error Code=" + e.getErrorCode());
System.out.println("Error Message=" + e.getMessage());
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (state != null) {
state.close();
}
if (conn != null) {
conn.close();
}
} catch (SQLException e) {
System.out.println("Error Code=" + e.getErrorCode());
System.out.println("Error Message=" + e.getMessage());
}
}
}
void fileExit_ActionPerformed(ActionEvent e) {
System.exit(0);
}
}
package XSCJ;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
public class courseInformation extends JFrame {
String[] column = { "课程号", "课程名称", "学生姓名" };
private JMenuBar menuBar = new JMenuBar();
private JMenu menuFile = new JMenu();
private JMenuItem menuFileExit = new JMenuItem();
private JTable courseTable = new JTable();
DefaultTableModel mm = new DefaultTableModel(column, 0) {
};
public courseInformation() {
try {
jbInit();
} catch (Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
this.setJMenuBar(menuBar);
this.getContentPane().setLayout(null);
this.setSize(new Dimension(489, 383));
this.setTitle("课程信息");
menuFile.setText("File");
menuFileExit.setText("Exit");
menuFileExit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
fileExit_ActionPerformed(ae);
}
});
courseTable.setBounds(new Rectangle(17, 35, 450, 260));
menuFile.add(menuFileExit);
menuBar.add(menuFile);
this.getContentPane().add(courseTable, null);
String courseNumber, courseName, teacherName;
Connection conn = null;
Statement state = null;
try {
Class.forName("oracle.jdbc.OracleDriver").newInstance();
conn =
DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XSCJ", "system",
"qazwsx");
state = conn.createStatement();
ResultSet rs =
state.executeQuery("select cno,cname,teacher.name from course,teacher where course.tno=teacher.tno");
while (rs.next()) {
courseNumber = rs.getString("cno");
courseName = rs.getString("cname");
teacherName = rs.getString("name");
Object[] courseInfo =
{ courseNumber, courseName, teacherName };
mm.addRow(courseInfo);
}
courseTable.setModel(mm);
rs.close();
} catch (SQLException e) {
System.out.println("Error Code=" + e.getErrorCode());
System.out.println("Error Message=" + e.getMessage());
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (state != null) {
state.close();
}
if (conn != null) {
conn.close();
}
} catch (SQLException e) {
System.out.println("Error Code=" + e.getErrorCode());
System.out.println("Error Message=" + e.getMessage());
}
}
}
void fileExit_ActionPerformed(ActionEvent e) {
System.exit(0);
}
}
//scoreInformation.java
package XSCJ;
import java.awt.Dimension;
import java.awt.Rectangle;
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;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
public class scoreInformation extends JFrame {
String[] column = { "学号", "课程号", "分数" };
private JMenuBar menuBar = new JMenuBar();
private JMenu menuFile = new JMenu();
private JMenuItem menuFileExit = new JMenuItem();
DefaultTableModel mm = new DefaultTableModel(column, 0) {
};
private JTable scoreTable = new JTable();
public scoreInformation() {
try {
jbInit();
} catch (Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
this.setJMenuBar(menuBar);
this.getContentPane().setLayout(null);
this.setSize(new Dimension(501, 437));
this.setTitle("成绩信息");
menuFile.setText("File");
menuFileExit.setText("Exit");
menuFileExit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
fileExit_ActionPerformed(ae);
}
});
scoreTable.setBounds(new Rectangle(25, 15, 445, 345));
menuFile.add(menuFileExit);
menuBar.add(menuFile);
this.getContentPane().add(scoreTable, null);
int degree;
String courseName, studentName;
Connection conn = null;
Statement state = null;
try {
Class.forName("oracle.jdbc.OracleDriver").newInstance();
conn =
DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XSCJ", "system",
"qazwsx");
state = conn.createStatement();
ResultSet rs =
state.executeQuery("select student.name,course.cname,score.degree from student,course,score where score.sno=student.sno and score.cno=course.cno");
while (rs.next()) {
studentName = rs.getString("name");
courseName = rs.getString("cname");
degree = rs.getInt("degree");
Object[] scoreInfo = { studentName, courseName, degree };
mm.addRow(scoreInfo);
}
scoreTable.setModel(mm);
rs.close();
} catch (SQLException e) {
System.out.println("Error Code=" + e.getErrorCode());
System.out.println("Error Message=" + e.getMessage());
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (state != null) {
state.close();
}
if (conn != null) {
conn.close();
}
} catch (SQLException e) {
System.out.println("Error Code=" + e.getErrorCode());
System.out.println("Error Message=" + e.getMessage());
}
}
}
void fileExit_ActionPerformed(ActionEvent e) {
System.exit(0);
}
}
package XSCJ;
import java.awt.Dimension;
import java.awt.Rectangle;
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;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
public class scoreInformation extends JFrame {
String[] column = { "学号", "课程号", "分数" };
private JMenuBar menuBar = new JMenuBar();
private JMenu menuFile = new JMenu();
private JMenuItem menuFileExit = new JMenuItem();
DefaultTableModel mm = new DefaultTableModel(column, 0) {
};
private JTable scoreTable = new JTable();
public scoreInformation() {
try {
jbInit();
} catch (Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
this.setJMenuBar(menuBar);
this.getContentPane().setLayout(null);
this.setSize(new Dimension(501, 437));
this.setTitle("成绩信息");
menuFile.setText("File");
menuFileExit.setText("Exit");
menuFileExit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
fileExit_ActionPerformed(ae);
}
});
scoreTable.setBounds(new Rectangle(25, 15, 445, 345));
menuFile.add(menuFileExit);
menuBar.add(menuFile);
this.getContentPane().add(scoreTable, null);
int degree;
String courseName, studentName;
Connection conn = null;
Statement state = null;
try {
Class.forName("oracle.jdbc.OracleDriver").newInstance();
conn =
DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XSCJ", "system",
"qazwsx");
state = conn.createStatement();
ResultSet rs =
state.executeQuery("select student.name,course.cname,score.degree from student,course,score where score.sno=student.sno and score.cno=course.cno");
while (rs.next()) {
studentName = rs.getString("name");
courseName = rs.getString("cname");
degree = rs.getInt("degree");
Object[] scoreInfo = { studentName, courseName, degree };
mm.addRow(scoreInfo);
}
scoreTable.setModel(mm);
rs.close();
} catch (SQLException e) {
System.out.println("Error Code=" + e.getErrorCode());
System.out.println("Error Message=" + e.getMessage());
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (state != null) {
state.close();
}
if (conn != null) {
conn.close();
}
} catch (SQLException e) {
System.out.println("Error Code=" + e.getErrorCode());
System.out.println("Error Message=" + e.getMessage());
}
}
}
void fileExit_ActionPerformed(ActionEvent e) {
System.exit(0);
}
}
还有大概45页的代码,太难复制粘贴了,而且浏览器已经很卡了,其实其他的代码和上面已经贴出来的差不多,我想的话根据上面的代码在去做其他的功能叶不需要多长时间,所以就不再贴代码了,昨天找了下当时的工程,发现已经找不到了,只剩下文档了。