Student Management Class: Adding, Deleting, Searching, and Changing Student Information
/**
-
The StudentManager class is responsible for managing student information. */ public class StudentManager {
/**
-
Adds a new student to the database.
-
@param t The Student object representing the new student.
-
@return True if the student information was successfully added, false otherwise.
-
@throws SQLException if there is an error in executing the SQL statement.
-
@throws UnknownHostException if the IP address of the host could not be determined.
-
@throws IOException if an I/O error occurs. */ public static boolean AddStudentInfo(Student t) throws SQLException, UnknownHostException, IOException { Message temp=new Message(); temp.addObject(t);
temp.changeOperateType("AddStudent");
boolean answer= ClientSR.sendAndReceive(temp,false);
return answer; }
/**
-
Deletes a student from the database.
-
@param id The ID of the student to be deleted.
-
@return True if the student information was successfully deleted, false otherwise.
-
@throws SQLException if there is an error in executing the SQL statement.
-
@throws UnknownHostException if the IP address of the host could not be determined.
-
@throws IOException if an I/O error occurs. */ public static boolean DeleteStudentInfo(String id) throws SQLException, UnknownHostException, IOException {
Message temp=new Message(); temp.addObject(id);temp.changeOperateType("DeleteStudent");
boolean answer= ClientSR.sendAndReceive(temp,false);
return answer;
}
/**
-
Searches for students in the database.
-
@param sname The name of the student to search for.
-
@return An ArrayList of Student objects matching the search criteria.
-
@throws SQLException if there is an error in executing the SQL statement.
-
@throws UnknownHostException if the IP address of the host could not be determined.
-
@throws IOException if an I/O error occurs. */ public static ArrayList<Student> SearchStudentInfo(String sname) throws SQLException, UnknownHostException, IOException { Message temp=new Message(); temp.addObject(sname);
temp.changeOperateType("SearchStudent"); ArrayList<Student> answer= ClientSR.sendAndReceive(temp,new ArrayList<Student>());
return answer;
}
/**
-
Changes the information of a student in the database.
-
@param t The Student object representing the updated student information.
-
@return True if the student information was successfully updated, false otherwise.
-
@throws SQLException if there is an error in executing the SQL statement.
-
@throws UnknownHostException if the IP address of the host could not be determined.
-
@throws IOException if an I/O error occurs. */ public boolean ChangeStudentInfo(Student t) throws SQLException, UnknownHostException, IOException { Message temp=new Message(); temp.addObject(t);
temp.changeOperateType("EditStudent");
boolean answer= ClientSR.sendAndReceive(temp,false);
return answer; }
static int idx=0; static int page_limit=10;
private static int max(int idx2, int i) { // TODO Auto-generated method stub int max=0; if(idx2>i) { max=idx2; } else max=i; return max; }
/**
- Displays a page of students from the database.
- @return An ArrayList of Student objects representing the students to be displayed.
- @throws UnknownHostException if the IP address of the host could not be determined.
- @throws IOException if an I/O error occurs. / static public ArrayList<Student> display() throws UnknownHostException, IOException { Message message = new Message(); message.addObject(page_limit); message.addObject(idxpage_limit); message.changeOperateType("GetAllStu"); ArrayList<Student> rooms= ClientSR.sendAndReceive(message,new ArrayList<Student>()); return rooms;
}
/**
-
Moves to the previous page of students in the database.
-
@return An ArrayList of Student objects representing the students on the previous page.
-
@throws UnknownHostException if the IP address of the host could not be determined.
-
@throws IOException if an I/O error occurs. */ public static ArrayList<Student> prev_page() throws UnknownHostException, IOException {
idx--; idx=max(idx,0); return display(); }
/**
- Moves to the next page of students in the database.
- @return An ArrayList of Student objects representing the students on the next page.
- @throws UnknownHostException if the IP address of the host could not be determined.
- @throws IOException if an I/O error occurs. */ public static ArrayList<Student> next_page() throws UnknownHostException, IOException { ArrayList<Student> list = display(); idx++; if(list.size()<10) { idx--; } return list; } }
-
原文地址: https://www.cveoy.top/t/topic/nTaA 著作权归作者所有。请勿转载和采集!