package com.source.managerDAL;
import com.source.model.JDBConnection;
import com.source.model.*;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.*;
import javax.resource.spi.ConnectionManager;
import javax.sql.*;
public class AdminManager {
private Connection conn;
private PreparedStatement titlesQuery;
private ResultSet results;
private JDBConnection jdbc=new JDBConnection();
private String sqlinto="update tbUsers set UserID=?,Password=?,Remark=? where UserID=?";
private String sqlinformation="update tbUserInfo set UserID=?,Username=?,Sex=?,StuClass=?,Specialty=?,Address=?" +
",Phone=?,Email=?,QQ=?,EnrollDate=?,Birthday=? where UserID=?";
private String sqlinfosel="select * from tbUserInfo";
private String sqlmess="select * from tbMessage";
private String sqlStuCour="select UserID,c.CourseID,Book,Ifqualified,ReCourse,IfRating,c.Course from tbStudentCourse sc join (select CourseID,Course from tbCourse)as c on sc.CourseID=c.CourseID";
private String sqlinfointo="insert into tbUserInfo (UserID,Username,StuClass) values(?,?,?)";
private String sqldel="delete tbUserInfo where UserID=?";
public static void main(String[] args) {
//new AdminManager().Stuinsets(f);
}
public int Stuinsets(UserInfo t, Users s,String birthday,String enrollDate)
{
int result=0;
Connection dbConnection=null;
PreparedStatement pStatement=null;
try
{
dbConnection=jdbc.getConnection();
//入学当前时间
// Calendar c=Calendar.getInstance();
// SimpleDateFormat f=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
//System.out.println(f.format(c.getTime()));
pStatement=dbConnection.prepareStatement(sqlinformation);
pStatement.setString(1, t.getUserID());
pStatement.setString(2, t.getUsername());
pStatement.setString(3, t.getSex());
pStatement.setString(4, t.getSpecialty());
pStatement.setString(5, t.getStuClass());
pStatement.setString(6, t.getAddress());
pStatement.setString(7, t.getPhone());
pStatement.setString(8, t.getEmail());
pStatement.setString(9, t.getQQ());
pStatement.setString(10,enrollDate);
pStatement.setString(11,birthday);
pStatement.setString(12,t.getUserID());
result=pStatement.executeUpdate();
dbConnection=jdbc.getConnection();
pStatement=dbConnection.prepareStatement(sqlinto);
pStatement.setString(1, s.getUserID());
pStatement.setString(2, s.getPassword());
pStatement.setString(3, s.getRemark());
pStatement.setString(4, s.getUserID());
result=pStatement.executeUpdate();
}
catch(SQLException SQLE)
{
SQLE.printStackTrace();
}
finally
{
closeData();
}
return result;
}
public int deles(String sid)
{
int result=0;
Connection dbConnection=null;
PreparedStatement pStatement=null;
try
{
dbConnection=jdbc.getConnection();
pStatement=dbConnection.prepareStatement(sqldel);
pStatement.setString(1,sid);
result=pStatement.executeUpdate();
}
catch(SQLException SQLE)
{
SQLE.printStackTrace();
}
finally
{
closeData();
}
return result;
}
public List Majorgets(){
List titlesList=new ArrayList();
List list=new ArrayList();
try{
conn=jdbc.getConnection();
titlesQuery=conn.prepareStatement("select * from tbMajor");
ResultSet results=titlesQuery.executeQuery();
while(results.next()){
Major Usf=new Major();
if(!list.contains(results.getInt("MajorID"))){
list.add(results.getInt("MajorID"));
Usf.setMajorID(results.getInt("MajorID"));
Usf.setMajor(results.getString("Major"));
titlesList.add(Usf);
}
}
}
catch(SQLException exception){
exception.printStackTrace();
}
finally{
closeData();
}
return titlesList;
}
public List StuInfogets(){
List titlesList=new ArrayList();
try{
conn=jdbc.getConnection();
titlesQuery=conn.prepareStatement(sqlinfosel);
ResultSet results=titlesQuery.executeQuery();
while(results.next()){
UserInfo Usf=new UserInfo();
Usf.setID(results.getInt("ID"));
Usf.setUserID(results.getString("UserID"));
Usf.setUsername(results.getString("Username"));
Usf.setSex(results.getString("Sex"));
Usf.setBirthday(results.getDate("Birthday"));
Usf.setSpecialty(results.getString("Specialty"));
Usf.setStuClass(results.getString("StuClass"));
Usf.setMajorID(results.getInt("MajorID"));
Usf.setProfessionalTitle(results.getString("ProfessionalTitle"));
Usf.setEnrollDate(results.getDate("EnrollDate"));
Usf.setPhone(results.getString("Phone"));
Usf.setAddress(results.getString("Address"));
Usf.setFamilyPhone(results.getString("FamilyPhone"));
Usf.setQQ(results.getString("QQ"));
Usf.setEmail(results.getString("Email"));
Usf.setPhoto(results.getString("Photo"));
Usf.setScore(results.getString("Score"));
titlesList.add(Usf);
}
}
catch(SQLException exception){
exception.printStackTrace();
}
finally{
closeData();
}
return titlesList;
}
public List message(){
List titlesList=new ArrayList();
try{
conn=jdbc.getConnection();
titlesQuery=conn.prepareStatement(sqlmess);
ResultSet results=titlesQuery.executeQuery();
while(results.next()){
Message Usf=new Message();
Usf.setID(results.getInt("ID"));
Usf.setUsername(results.getString("Username"));
Usf.setTitle(results.getString("Title"));
Usf.setCon(results.getString("Content"));
Usf.setMessageTime(results.getDate("MessageTime"));
titlesList.add(Usf);
}
}
catch(SQLException exception){
exception.printStackTrace();
}
finally{
closeData();
}
return titlesList;
}
public List StuCours(){
List titlesList=new ArrayList();
try{
conn=jdbc.getConnection();
titlesQuery=conn.prepareStatement(sqlStuCour);
ResultSet results=titlesQuery.executeQuery();
while(results.next()){
StudentCourse Usf=new StudentCourse();
Usf.setUserID(results.getString("UserID"));
Usf.setCourseID(results.getInt("CourseID"));
Usf.setBook(results.getBoolean("Book"));
Usf.setIfqualified(results.getBoolean("Ifqualified"));
Usf.setReCourse(results.getBoolean("ReCourse"));
Usf.setIfRating(results.getBoolean("IfRating"));
Usf.setCourse(results.getString("course"));
titlesList.add(Usf);
}
}
catch(SQLException exception){
exception.printStackTrace();
}
finally{
closeData();
}
return titlesList;
}
public int Stuinsets(UserInfo t)
{
int result=0;
Connection dbConnection=null;
PreparedStatement pStatement=null;
try
{
dbConnection=jdbc.getConnection();
pStatement=dbConnection.prepareStatement(sqlinfointo);
pStatement.setString(1, t.getUserID());
pStatement.setString(2, t.getUsername());
pStatement.setString(3, t.getStuClass());
result=pStatement.executeUpdate();
}
catch(SQLException SQLE)
{
SQLE.printStackTrace();
}
finally
{
closeData();
}
return result;
}
public int delestucour(String sid)
{
int result=0;
Connection dbConnection=null;
PreparedStatement pStatement=null;
try
{
dbConnection=jdbc.getConnection();
pStatement=dbConnection.prepareStatement("delete tbStudentCourse where CourseID=?");
pStatement.setString(1,sid);
result=pStatement.executeUpdate();
}
catch(SQLException SQLE)
{
- 1
- 2
前往页