📄 impl.java
字号:
package cn.com.dao.classmanagerdao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JOptionPane;
import cn.com.dialog.classmanagerdialog.classintercalate.ClassIntercalateAdd;
import cn.com.dialog.classmanagerdialog.classintercalate.ClassUpdate;
import cn.com.util.DBConnection;
import cn.com.util.calsssystemcommon.ClassSystemDBsql;
import cn.com.vo.classmanagervo.ClassStudentVo;
import cn.com.vo.classmanagervo.ClassVO;
public class Impl {
/**
* 添加新的课程
*
* @param vo
* @return
*/
public boolean appendClass(ClassVO vo) {
boolean flag = false;
Connection conn = null;
PreparedStatement pstmt = null;
conn = DBConnection.getConnectionOracle();
if (checkClassExit(conn, vo.getClassID())) {
JOptionPane.showMessageDialog(null, "课程编号已经存在,请重新输入!");
}
try {
pstmt = conn.prepareStatement(ClassSystemDBsql.CLASS_APPEND);
pstmt.setInt(1, vo.getClassID());
pstmt.setString(2, vo.getClassname());
pstmt.setInt(3, vo.getCredithour());
pstmt.setInt(4, vo.getTotaltime());
pstmt.setString(5, vo.getClassestate());
pstmt.setString(6, vo.getClasstime());
pstmt.setInt(7, vo.getTeacherID());
pstmt.setString(8, vo.getClassremark());
int count = pstmt.executeUpdate();
if (count != 0) {
flag = true;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return flag;
}
/**
* 修改课程信息
*/
public boolean updateClass(ClassVO vo) {
boolean flag = false;
Connection conn = null;
PreparedStatement pstmt = null;
conn = DBConnection.getConnectionOracle();
try {
pstmt = conn.prepareStatement(ClassSystemDBsql.C_T_UPDATE);
pstmt.setString(1, vo.getClassname());
pstmt.setInt(2, vo.getCredithour());
pstmt.setInt(3, vo.getTotaltime());
pstmt.setString(4, vo.getClassestate());
pstmt.setInt(5, vo.getTeacherID());
pstmt.setString(6, vo.getClasstime());
pstmt.setString(7, vo.getClassremark());
pstmt.setInt(8, vo.getClassID());
int count = pstmt.executeUpdate();
if (count != 0) {
flag = true;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return flag;
}
/**
* 删除所选择的课程信息
*/
public boolean classDelete(int classNo) {
boolean flag = false;
Connection conn = null;
PreparedStatement pstmt = null;
conn = DBConnection.getConnectionOracle();
try {
pstmt = conn.prepareStatement(ClassSystemDBsql.CLASS_DELETE);
pstmt.setInt(1, classNo);
int count = pstmt.executeUpdate();
if (count != 0) {
flag = true;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return flag;
}
/**
* 根据学号查找学生信息
*/
public ResultSet stuFind(int stuNo) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet set = null;
conn = DBConnection.getConnectionOracle();
try {
pstmt = conn.prepareStatement(ClassSystemDBsql.STU_FIND);
pstmt.setInt(1, stuNo);
set = pstmt.executeQuery();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return set;
}
/**
* 根据学号查找所选课程
*/
public Object[][] FindC_TByNo(int stuNo) {
Object[][] data = null;
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet set = null;
conn = DBConnection.getConnectionOracle();
try {
pstmt = conn
.prepareStatement(" select c.classnum,classname,totaltime,classtime,credithour,classestate,t.t_id,t_name,t_duty,classremake from studentinfotable s,"
+ " classtable c,studentexamchivement e,teacherinfotable t "
+ "where s.s_id = e.s_id and e.classnum = c.classnum and c.t_id = t.t_id and s.s_id = ? order by s.s_id");
pstmt.setInt(1, stuNo);
set = pstmt.executeQuery();
int i = 0;
int number = getNumberByNo(stuNo);
int max = set.getMetaData().getColumnCount();
data = new Object[number][max];
while (set.next()) {
for (int j = 0; j < max; j++) {
data[i][j] = set.getObject(j + 1);
}
i++;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return data;
}
/**
* 根据老师编号查找姓名,并返回
*
* @param teacherNo
* @return
*/
public static String findTeacherByNo(int teacherNo) {
String name = null;
PreparedStatement pstmt = null;
Connection con = null;
ResultSet set = null;
try {
con = DBConnection.getConnectionOracle();
pstmt = con.prepareStatement(ClassSystemDBsql.T_NAME_FIND);
pstmt.setInt(1, teacherNo);
set = pstmt.executeQuery();
if (set.next()) {
name = set.getString(1);
}
} catch (Exception e) {
System.out.println("根据编号查找老师dao异常:" + e.getMessage());
}
return name;
}
/**
* 检查输入的课程编号是否存在
*
* @param con
* @param classNo
* @return
*/
private boolean checkClassExit(Connection coon, int classNo) {
boolean flag = false;
PreparedStatement pstmt = null;
ResultSet set = null;
try {
pstmt = coon.prepareStatement(ClassSystemDBsql.CLASS_SELECT);
pstmt.setInt(1, classNo);
set = pstmt.executeQuery();
while (set.next()) {
flag = true;
}
} catch (SQLException e) {
System.out.println(e.getMessage());
}
return flag;
}
/**
* 检查输入的课程编号是否存在
*
* @param con
* @param classNo
* @return
*/
public boolean checkClassEx( int classNo) {
boolean flag = false;
Connection coon = DBConnection.getConnectionOracle();
PreparedStatement pstmt = null;
ResultSet set = null;
try {
pstmt = coon.prepareStatement(ClassSystemDBsql.CLASS_SELECT);
pstmt.setInt(1, classNo);
set = pstmt.executeQuery();
while (set.next()) {
flag = true;
}
} catch (SQLException e) {
System.out.println(e.getMessage());
}
return flag;
}
/**
* 学生选课
* @param stuNo
* @param classNo
* @return
*/
public boolean classChooseByStu(int stuNo,int classNo){
boolean flag = false;
Connection conn = null;
PreparedStatement pstmt = null;
conn = DBConnection.getConnectionOracle();
try {
pstmt = conn.prepareStatement(ClassSystemDBsql.CLASS_CHOOSE);
pstmt.setInt(1, stuNo);
pstmt.setInt(2, classNo);
int count = pstmt.executeUpdate();
if(count != 0){
flag = true;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return flag;
}
/**
*
* @param classNo
* @return
*/
public static ResultSet classinfo(int classNo) {
PreparedStatement pstmt = null;
Connection conn = null;
ResultSet set = null;
try {
conn = DBConnection.getConnectionOracle();
pstmt = conn.prepareStatement(ClassSystemDBsql.C_T_FIND);
pstmt.setInt(1, classNo);
set = pstmt.executeQuery();
} catch (Exception e) {
System.out.println("根据编号查找老师dao异常:" + e.getMessage());
}
return set;
}
/**
* 查找所有的课程信息和执教老师信息
*
* @return
*/
public Object[][] getClassInfo() {
Object[][] data = null;
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet set = null;
conn = DBConnection.getConnectionOracle();
try {
pstmt = conn.prepareStatement(ClassSystemDBsql.ALLCLASS_INFO);
set = pstmt.executeQuery();
int max = set.getMetaData().getColumnCount();
int number = getNumber();
System.out.println(number);
int i = 0;
data = new Object[number][max];
while (set.next()) {
for (int j = 0; j < max; j++) {
data[i][j] = set.getObject(j + 1);
}
i++;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return data;
}
/**
* 获得课程的总数目
*/
public int getNumber() {
int number = 0;
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet set = null;
conn = DBConnection.getConnectionOracle();
try {
pstmt = conn.prepareStatement(ClassSystemDBsql.CLASS_DATA);
set = pstmt.executeQuery();
set.next();
number = set.getInt(1);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return number;
}
/**
* 根据老师编号获得课程的总数目
*/
public int getNumberByTNo(int t_id) {
int number = 0;
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet set = null;
conn = DBConnection.getConnectionOracle();
try {
pstmt = conn.prepareStatement(ClassSystemDBsql.T_COUNT);
pstmt.setInt(1, t_id);
set = pstmt.executeQuery();
set.next();
number = set.getInt(1);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return number;
}
/**
* 根据学号获得课程的总数目
*/
public int getNumberByNo(int stuNo) {
int number = 0;
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet set = null;
conn = DBConnection.getConnectionOracle();
try {
pstmt = conn
.prepareStatement("select count(*) from studentinfotable s, classtable c,studentexamchivement e,"
+ "teacherinfotable t where s.s_id = e.s_id and e.classnum = c.classnum and "
+ "c.t_id = t.t_id and s.s_id = ? order by s.s_id");
pstmt.setInt(1, stuNo);
set = pstmt.executeQuery();
set.next();
number = set.getInt(1);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return number;
}
/**
* 根据老师编号查询其所教课程
*/
public Object[][] ClassFindByTNo(int t_id) {
Object[][] data = null;
Connection conn = null;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -