ManagerResponse Class for Student Management
/**
-
This class represents the response from the manager. It contains methods for adding, deleting, searching, updating, and displaying student information. */ public class ManagerResponse {
/**
-
Adds a new student to the database.
-
@param message The message containing the student information.
-
@param clientSocket The socket used to send the response back to the client.
-
@return True if the student was successfully added, false otherwise.
-
@throws SQLException If there is an error accessing the database. */ public static boolean AddStudent(Message message, Socket clientSocket) throws SQLException {
Student temp = (Student) message.getObjectList().get(0);
//User us=(User) message.getObjectList().get(0); // Perform the operation to add the student information boolean ok=false; ok=StudentDao.create(temp); ServerSR.sendObject(ok, clientSocket); return ok; }
/**
-
Deletes a student from the database.
-
@param message The message containing the student information.
-
@param clientSocket The socket used to send the response back to the client.
-
@return True if the student was successfully deleted, false otherwise.
-
@throws SQLException If there is an error accessing the database. */ public static boolean DeleteStudent(Message message, Socket clientSocket) throws SQLException {
//Student temp = (Student) message.getObjectList().get(0); String temp=(String) message.getObjectList().get(0); //User us=(User) message.getObjectList().get(0); // Perform the operation to add the student information boolean ok = false; ok=StudentDao.deleteById(temp); // Send the response back to the client ServerSR.sendObject(ok, clientSocket); return ok; }
/**
- Searches for a student by their name.
- @param message The message containing the student name to search for.
- @param clientSocket The socket used to send the response back to the client.
- @return An ArrayList of students that match the search criteria.
- @throws SQLException If there is an error accessing the database.
*/
public static ArrayList
StudentSearchByName(Message message, Socket clientSocket) throws SQLException { String temp = (String) message.getObjectList().get(0); ArrayList ok; // findByName method searches by name. Duplicate names might exist, so it returns a list of student information System.out.println('inside the function '+clientSocket); ok =StudentDao.findByName(temp); System.out.println('inside the function middle'+clientSocket); ServerSR.sendObject(ok, clientSocket); System.out.println('inside the function last '+clientSocket); return ok; }
/**
- Updates a student's information.
- @param message The message containing the updated student information.
- @param clientSocket The socket used to send the response back to the client.
- @return True if the student information was successfully updated, false otherwise.
- @throws SQLException If there is an error accessing the database. */ public static boolean Update(Message message, Socket clientSocket) throws SQLException { Student temp = (Student) message.getObjectList().get(0); boolean ok; // update method updates the record based on the provided student data. It returns true if successful, otherwise false. ok = StudentDao.update(temp); ServerSR.sendObject(ok, clientSocket); return ok; }
/**
-
Displays a specified number of student records.
-
@param message The message containing the limit and offset values for displaying the records.
-
@param clientSocket The socket used to send the response back to the client.
-
@throws SQLException If there is an error accessing the database. */ public static void Display(Message message,Socket clientSocket) throws SQLException { int limit = (int)message.getObjectList().get(0); int offset = (int)message.getObjectList().get(1);
// Perform the operation to display the student records ArrayList
books=StudentDao.display(limit, offset); ServerSR.sendObject(books, clientSocket);
}
-
}
原文地址: https://www.cveoy.top/t/topic/nSYK 著作权归作者所有。请勿转载和采集!