📄 csbean.java
字号:
package Cstudent;
import java.util.*;
import java.sql.*;
import javax.swing.*;
/**
* 用来保存成绩查询方面的类
*/
public class csBean {
String sql;
ResultSet rs;
Vector tempvector=new Vector(1,1);
String Cno;
String Sno;
float Grade;
int colNum;
/**
* 添加学生的选课信息
*/
public void csAdd(String cno, String sno){
Database DB = new Database();
this.Cno = cno;
this.Sno = sno;
sql = "insert into SC(Cno,Sno) values ("+Integer.parseInt(Cno)+","+Integer.parseInt(Sno)+")";
try{
DB.OpenConn();
DB.executeUpdate(sql);
JOptionPane.showMessageDialog(null,"成功添加一条新的纪录!");
}
catch(Exception e){
JOptionPane.showMessageDialog(null, "保存失败", "错误", JOptionPane.ERROR_MESSAGE);
}
finally {
DB.closeStmt();
DB.closeConn();
}
}
/**
* 修改学生的选课成绩
*/
public void csModify(String cno, String sno, String grade){
Database DB = new Database();
this.Cno = cno;
this.Sno = sno;
try{
this.Grade = Float.parseFloat(grade);
}
catch(Exception e){
JOptionPane.showMessageDialog(null, "成绩输入错误", "错误", JOptionPane.ERROR_MESSAGE);
return;
}
sql = "update SC set Grade = "+Grade+" where Sno = "+Integer.parseInt(Sno)+" and Cno = "+Integer.parseInt(Cno)+" ";
try{
DB.OpenConn();
DB.executeUpdate(sql);
JOptionPane.showMessageDialog(null,"成功登记成绩!");
}
catch(Exception e){
System.out.println(e);
JOptionPane.showMessageDialog(null, "登记失败", "错误", JOptionPane.ERROR_MESSAGE);
}
finally {
DB.closeStmt();
DB.closeConn();
}
}
/**
* 根据学号搜索其所选的课程名称
*/
public String[] cNameSearch(String sno){
Database DB = new Database();
this.Sno = sno;
sql = "select * from SC,Course where SC.Sno = "+Integer.parseInt(Sno)+" and SC.Cno = Course.Cno";
String[] cn = null;
int row = 0;
int i = 0;
try{
DB.OpenConn();
rs = DB.executeQuery(sql);
if(rs.last()){
row = rs.getRow();
}
if(row == 0){
cn = null;
}
else{
cn = new String[row];
rs.first();
rs.previous();
while(rs.next()){
cn[i] = rs.getString(5);
i++;
}
}
}
catch(Exception e){
}
finally {
DB.closeStmt();
DB.closeConn();
}
return cn;
}
/**
* 成绩信息综合查询
*/
public String[][] csAllSearch(String sno, int colnum){
this.Sno = sno;
this.colNum = colnum;
Database DB = new Database();
String[][] cn = null;
int row = 0;
int i = 0;
sql = "select * from SC,Course,Student where SC.Sno = "+Integer.parseInt(Sno)+" and SC.Cno = Course.Cno and SC.Sno = Student.Sno";
try{
DB.OpenConn();
rs = DB.executeQuery(sql);
if(rs.last()){
row = rs.getRow();
}
if(row == 0){
cn = null;
}
else{
cn = new String[row][8];
rs.first();
rs.previous();
while(rs.next()){
cn[i][0] = rs.getString(1);
cn[i][2] = rs.getString(2);
cn[i][4] = rs.getString(3);
cn[i][3] = rs.getString(5);
cn[i][1] = rs.getString(11);
i++;
}
}
}
catch(Exception e){
}
finally {
DB.closeStmt();
DB.closeConn();
}
return cn;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -