📄 mainframe.java
字号:
public void excesql(String s1)
{
try
{
conBuild();
Statement statement = conn.createStatement();
statement.executeUpdate(s1);
myWindow.repaint();
jl2.setText("操作已执行");
System.out.println((new StringBuilder()).append("成功执行:").append(s1).toString());
MainFrame _tmp = this;
closeDB();
}
catch(Exception exception)
{
jl2.setText("无法执行,请填入正确的数据");
System.out.println((new StringBuilder()).append(s1).append("无法执行").toString());
}
}
public static void regDriver()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
System.out.println("驱动注册成功");
}
catch(Exception exception)
{
System.out.println("无法创建驱动程序实体!");
}
}
public static void conBuild()
{
try
{
regDriver();
conn = DriverManager.getConnection("jdbc:odbc:ScoreSystem", "", "");
conn.setAutoCommit(true);
System.out.println("连接数据库成功!");
}
catch(Exception exception)
{
System.out.println(exception.getMessage());
System.out.println("无法连接数据库!,请检查是否设置好数据源!");
}
}
public static ResultSet execQuery(String s1)
{
try
{
conBuild();
comm = conn.createStatement();
rs = comm.executeQuery(s1);
return rs;
}
catch(Exception exception)
{
System.out.println("创建Statement失败!");
}
return null;
}
public static void closeDB()
{
try
{
comm.close();
conn.close();
System.out.println("关闭记录,断开数据库");
}
catch(Exception exception)
{
System.out.println(exception.getMessage());
}
}
public void actionPerformed(ActionEvent actionevent)
{
if(actionevent.getSource() == dl)
{
s.setVisible(true);
carddl.setVisible(false);
cardwc.setVisible(true);
jl2.setText("登陆成功!");
System.out.println("登陆成功!");
}
if(actionevent.getSource() == courseMath)
{
scourse = "Math";
exce((new StringBuilder()).append("SELECT * FROM ").append(scourse).append(" order by stuid").toString());
myWindow.repaint();
hidecard();
cardwc.setVisible(true);
jl2.setText("你选择了管理[高等数学]学生成绩");
jl3.setText("10班第二小组《学生成绩管理系统》,正在管理的课程是:高等数学");
System.out.println("选择了管理[高等数学]学生成绩");
}
if(actionevent.getSource() == courseJava)
{
scourse = "Java";
exce((new StringBuilder()).append("SELECT * FROM ").append(scourse).append(" order by stuid").toString());
myWindow.repaint();
hidecard();
cardwc.setVisible(true);
jl2.setText("你选择了管理[Java程序设计]学生成绩");
jl3.setText("10班第二小组《学生成绩管理系统》,正在管理的课程是:Java程序设计");
System.out.println("选择了管理[Java程序设计]学生成绩");
}
if(actionevent.getSource() == courseC)
{
scourse = "C";
exce((new StringBuilder()).append("SELECT * FROM ").append(scourse).append(" order by stuid").toString());
myWindow.repaint();
hidecard();
cardwc.setVisible(true);
jl2.setText("你选择了管理[C语言]学生成绩");
jl3.setText("10班第二小组《学生成绩管理系统》,正在管理的课程是:C语言");
System.out.println("选择了管理[C语言]学生成绩");
}
if(actionevent.getSource() == courseDatastr)
{
scourse = "Datastr";
exce((new StringBuilder()).append("SELECT * FROM ").append(scourse).append(" order by stuid").toString());
myWindow.repaint();
hidecard();
cardwc.setVisible(true);
jl2.setText("你选择了管理[数据结构]学生成绩");
jl3.setText("10班第二小组《学生成绩管理系统》,正在管理的课程是:数据结构");
System.out.println("选择了管理[数据结构]学生成绩");
}
if(actionevent.getSource() == courseDatabank)
{
scourse = "Databank";
exce((new StringBuilder()).append("SELECT * FROM ").append(scourse).append(" order by stuid").toString());
myWindow.repaint();
hidecard();
cardwc.setVisible(true);
jl2.setText("你选择了管理[数据库]学生成绩");
jl3.setText("10班第二小组《学生成绩管理系统》,正在管理的课程是:数据库");
System.out.println("选择了管理[数据库]学生成绩");
}
if(actionevent.getSource() == courseSystem)
{
scourse = "System";
exce((new StringBuilder()).append("SELECT * FROM ").append(scourse).append(" order by stuid").toString());
myWindow.repaint();
hidecard();
cardwc.setVisible(true);
jl2.setText("你选择了管理[操作系统]学生成绩");
jl3.setText("10班第二小组《学生成绩管理系统》,正在管理的课程是:操作系统");
System.out.println("选择了管理[操作系统]学生成绩");
}
if(actionevent.getSource() == Record)
try
{
jid.setText("");
jname.setText("");
jscore.setText("");
myWindow.repaint();
hidecard();
cardRecord.setVisible(true);
jl2.setText("选择录入操作");
}
catch(Exception exception)
{
jl2.setText("你的选择有误");
}
if(actionevent.getSource() == Find)
try
{
se.setText("");
myWindow.repaint();
hidecard();
cardFind.setVisible(true);
jl2.setText("选择查询操作");
}
catch(Exception exception1)
{
jl2.setText("你的选择有误");
}
if(actionevent.getSource() == Redel)
try
{
jid.setText("");
jname.setText("");
jscore.setText("");
myWindow.repaint();
hidecard();
cardRedel.setVisible(true);
jl2.setText("选择修改或删除操作");
}
catch(Exception exception2)
{
jl2.setText("你的选择有误");
}
if(actionevent.getSource() == Refurbish)
{
exce((new StringBuilder()).append("SELECT * FROM ").append(scourse).append(" order by stuid").toString());
jid.setText("");
jname.setText("");
jscore.setText("");
myWindow.repaint();
hidecard();
cardRedel.setVisible(true);
jl2.setText("提示:刷新成功");
}
if(actionevent.getSource() == ss)
{
exce((new StringBuilder()).append("SELECT * FROM ").append(scourse).append(" order by stuid").toString());
se.setText("");
hidecard();
cardFind.setVisible(true);
jl2.setText("提示:刷新成功");
}
if(actionevent.getSource() == Stuids)
{
exce((new StringBuilder()).append("SELECT * FROM ").append(scourse).append(" order by stuid").toString());
jid.setText("");
jname.setText("");
jscore.setText("");
myWindow.repaint();
hidecard();
cardRedel.setVisible(true);
jl2.setText("排序成功");
}
if(actionevent.getSource() == Stuidz)
{
exce((new StringBuilder()).append("SELECT * FROM ").append(scourse).append(" order by stuid desc").toString());
jid.setText("");
jname.setText("");
jscore.setText("");
myWindow.repaint();
hidecard();
cardRedel.setVisible(true);
jl2.setText("排序成功");
}
if(actionevent.getSource() == Scores)
{
exce((new StringBuilder()).append("SELECT * FROM ").append(scourse).append(" order by score").toString());
jid.setText("");
jname.setText("");
jscore.setText("");
myWindow.repaint();
hidecard();
cardRedel.setVisible(true);
jl2.setText("排序成功");
}
if(actionevent.getSource() == Scorez)
{
exce((new StringBuilder()).append("SELECT * FROM ").append(scourse).append(" order by score desc").toString());
jid.setText("");
jname.setText("");
jscore.setText("");
myWindow.repaint();
hidecard();
cardRedel.setVisible(true);
jl2.setText("排序成功");
}
if(actionevent.getSource() == add2)
{
excesql((new StringBuilder()).append("insert into ").append(scourse).append(" values('").append(jid2.getText()).append("','").append(jname2.getText()).append("','").append(jscore2.getText()).append("')").toString());
exce((new StringBuilder()).append("SELECT * FROM ").append(scourse).append(" order by stuid").toString());
jid2.setText("");
jname2.setText("");
jscore2.setText("");
myWindow.repaint();
hidecard();
cardRecord.setVisible(true);
jl2.setText("提示:添加成功");
System.out.println("执行添加操作");
}
if(actionevent.getSource() == drop)
{
excesql((new StringBuilder()).append("update ").append(scourse).append(" set name='").append(jname.getText()).append("' ,score='").append(jscore.getText()).append("' where stuid='").append(jid.getText()).append("'").toString());
exce((new StringBuilder()).append("SELECT * FROM ").append(scourse).append(" order by stuid").toString());
jid.setText("");
jname.setText("");
jscore.setText("");
myWindow.repaint();
hidecard();
cardRedel.setVisible(true);
jl2.setText("提示:修改成功");
}
if(actionevent.getSource() == del)
{
excesql((new StringBuilder()).append("DELETE FROM ").append(scourse).append(" WHERE stuid='").append(jid.getText()).append("'").toString());
exce((new StringBuilder()).append("SELECT * FROM ").append(scourse).append(" order by stuid").toString());
jid.setText("");
jname.setText("");
jscore.setText("");
myWindow.repaint();
hidecard();
cardRedel.setVisible(true);
jl2.setText((new StringBuilder()).append("提示:成功删除学号为").append(jid.getText()).append("的数据").toString());
System.out.println("执行删除操作");
}
if(actionevent.getSource() == jbse)
{
if(data2List.getSelectedIndex() >= 4)
{
String s1 = (new StringBuilder()).append("SELECT * FROM ").append(scourse).append(" WHERE ").append(data2List.getSelectedItem()).append(se.getText()).toString();
exce(s1);
} else
{
System.out.println("执行删");
String s2 = (new StringBuilder()).append("SELECT * FROM ").append(scourse).append(" WHERE ").append(data2List.getSelectedItem()).append("'").append(se.getText()).append("'").toString();
exce(s2);
}
myWindow.repaint();
hidecard();
cardFind.setVisible(true);
jl2.setText("提示:成功查询学生数据");
System.out.println("执行查询操作");
}
if(actionevent.getSource() == Aboutme)
{
String s3 = "关于本程序";
String s4 = "学生成绩管理系统 Besign By 刘东成、甘超龙、朱飞跃、骆燕玲、曹宇明、孙东杰和赵放。";
int j = -1;
j = 1;
JOptionPane.showMessageDialog(null, s4, s3, j);
}
if(actionevent.getSource() == Outlogin)
{
System.out.println("退出程序!");
System.exit(0);
}
}
public void valueChanged(ListSelectionEvent listselectionevent)
{
row = 0;
row = jt.getSelectedRow();
if(row < 0)
row = 0;
Object obj = jt.getValueAt(row, 0);
Object obj1 = jt.getValueAt(row, 1);
Object obj2 = jt.getValueAt(row, 2);
hidecard();
cardRedel.setVisible(true);
jid.setText(obj.toString());
jname.setText(obj1.toString());
if(obj2 != null)
jscore.setText(obj2.toString());
else
jscore.setText("0");
row++;
System.out.println((new StringBuilder()).append("选择了第").append(row).append("行").toString());
jl2.setText((new StringBuilder()).append("你选择了第").append(row).append("行").toString());
}
public static void main(String args[])
{
MainFrame mainframe = new MainFrame();
mainframe.myWindow.setBounds(50, 50, 500, 580);
String s1 = "SELECT * FROM Math order by stuid";
mainframe.exce(s1);
mainframe.myWindow.setVisible(true);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -