this is some of the coding...
private University(){
name = "World Virtual University";
studentList = new ArrayList();
employeeList = new ArrayList();
classroomList = new ArrayList();
startConnection();
}
public String getUniversityName(){
return name;
}
public Student getStudent(int value){
return (Student)studentList.get(value);
}
public Iterator getAllStudent(){
return studentList.iterator();
}
public Classroom getClassroom(int value){
return (Classroom)classroomList.get(value);
}
public Iterator getAllClassroom(){
return classroomList.iterator();
}
public Staff getStaff(int value){
Object e = employeeList.get(value);
if (e instanceof Administrator)
return (Administrator)e;
else if (e instanceof Lecturer)
return (Lecturer)e;
else if (e instanceof Manager)
return (Manager)e;
else return (Staff)e;
}
public int getStaffNumber(){
return employeeList.size();
}
public Iterator getAllStaff(){
return employeeList.iterator();
}
public void addStaff(String staffID,String name,String boGender,
String ic,String address,String telhome,
String telhp,String fax,String email,
String password,String remark,
String boGroupType,String position,String salary,
String department){
try{
Statement statement1 = connection.createStatement();
String valid = "SELECT * FROM Student WHERE staffid ='" +
staffID + "'";
ResultSet rs = statement1.executeQuery(valid);
if ( rs.next()){
JOptionPane.showMessageDialog(null,"Duplicate Staff ID Found!",
"Error", JOptionPane.ERROR_MESSAGE);
return;
}
}catch(SQLException sqlex){}
try{
if (validateStaffAction(staffID,name,boGender,ic,address,telhome,telhp,fax,email,
password,remark,boGroupType,position,salary,department)){
Statement statement = connection.createStatement();
String query = "INSERT INTO Staff(staffid,name,gender,ic,address,telhome,telhp,fax,email,password,remark,grouptype,employedas,salary,department) "+
"VALUES ('" + staffID + "', '" + name + "', '" + boGender +
"', '" + ic + "', '" + address + "', '" + telhome + "', '" +
telhp + "', '" + fax + "', '" + email + "', '" + password + "', '" +
remark + "', '" + boGroupType + "', '" + position + "', '" +
salary + "', '" + department + "')";
int result = statement.executeUpdate(query);
if ( result == 1 ){
double sa = Double.parseDouble(salary);
if( boGender.equalsIgnoreCase("1") ){
employeeList.add(new Staff(staffID,name,boGender,ic,address,
telhome,telhp,fax,email,password,remark,position,sa,department));
}else if ( boGender.equalsIgnoreCase("2") ){
employeeList.add(new Administrator(staffID,name,boGender,ic,address,
telhome,telhp,fax,email,password,remark,position,sa,department));
}else if ( boGender.equalsIgnoreCase("3") ){
employeeList.add(new Manager(staffID,name,boGender,ic,address,
telhome,telhp,fax,email,password,remark,position,sa,department));
}else if ( boGender.equalsIgnoreCase("4") ){//lecturer
Lecturer a = new Lecturer(staffID,name,boGender,ic,address,
telhome,telhp,fax,email,password,remark,position,sa,department);
employeeList.add(a);
}
JOptionPane.showMessageDialog(null,"Insertion Sucess",
"Insertion",JOptionPane.INFORMATION_MESSAGE);
}else JOptionPane.showMessageDialog(null,"Insertion Failed",
"Insertion",JOptionPane.INFORMATION_MESSAGE);
}
}catch(SQLException sqlex){
sqlex.printStackTrace();
System.out.println(sqlex.toString());
JOptionPane.showMessageDialog(null,sqlex.toString());
}
}
public void addStudent(String studentID, String name, String boGender,
String ic,String address,String telhome,
String telhp,String fax,String email,
String password,String remark,String intakeid){
try{
Statement statement1 = connection.createStatement();
String valid = "SELECT * FROM Student WHERE studentid ='" +
studentID + "'";
ResultSet rs = statement1.executeQuery(valid);
if ( rs.next()){
JOptionPane.showMessageDialog(null,"Duplicate Student ID Found!",
"Error", JOptionPane.ERROR_MESSAGE);
}
}catch(SQLException sqlex){}
try{
if (validateStudentAction(studentID, name, boGender,ic,address,telhome,telhp,fax,email,
password,remark,intakeid)){
Statement statement = connection.createStatement();
String query = "INSERT INTO Student(studentid,name,gender,ic,address,telhome,telhp,fax,email,password,remark,intakeid) "+
"VALUES ('" + studentID + "', '" + name + "', '" + boGender + "', '" +
ic + "', '" + address + "', '" + telhome + "', '" + telhp + "', '" +
fax + "', '" + email + "', '" + password + "', '" + remark + "', '" +
intakeid + "')";
int result = statement.executeUpdate(query);
if ( result == 1 ){
studentList.add(new Student(studentID,name,boGender,ic,address,telhome,telhp,fax,
email,password,remark,intakeid,0));
JOptionPane.showMessageDialog(null,"Insertion Sucess",
"Insertion",JOptionPane.INFORMATION_MESSAGE);
}else{
JOptionPane.showMessageDialog(null,"Insertion Failed",
"Insertion",JOptionPane.INFORMATION_MESSAGE);
}
}
}catch(SQLException sqlex){
sqlex.printStackTrace();
System.out.println(sqlex.toString());
JOptionPane.showMessageDialog(null,sqlex.toString());
}
}
public void addClassroom(String classroomid,String type,String maxpeople,
String aircon,String mic,String projector,String computer){
try{
Statement statement1 = connection.createStatement();
String valid = "SELECT * FROM Classroom WHERE classroomID = '" +
classroomid + "'";
ResultSet rs = statement1.executeQuery(valid);
if (rs.next()){
JOptionPane.showMessageDialog(null, "No Duplicate Classroom ID.", "Error",
JOptionPane.ERROR_MESSAGE);
rs.close();
statement1.close();
return;
}
}catch(SQLException sqlex){
sqlex.printStackTrace();
JOptionPane.showMessageDialog(null, sqlex.getMessage());
}
try{
if(validateClassroomAction(classroomid,type,maxpeople,aircon,mic,
projector,computer)){
Statement statement = connection.createStatement();
String query = "INSERT INTO Classroom(classroomID, type, maxpeople, aircon, mic, projector, computer) " +
"VALUES ('" + classroomid + "', '" +
type + "', '" + maxpeople + "', '" +
aircon + "', '" + mic + "', '" + projector + "', '" + computer + "')";
int result = statement.executeUpdate(query);
if (result == 1){
JOptionPane.showMessageDialog(null, "Insertion Success",
"Insertion", JOptionPane.INFORMATION_MESSAGE);
this.classroomList.add(new Classroom(classroomid,type,maxpeople,aircon,mic,projector,computer));
}else JOptionPane.showMessageDialog(null, "Insertion Failed");
}
}catch(SQLException sqlex){
sqlex.printStackTrace();
JOptionPane.showMessageDialog(null, sqlex.getMessage());
}
}
public boolean delStaff(String staffID){
try{
Statement statement = connection.createStatement();
String query = "DELETE FROM Staff WHERE staffid ='" + staffID + "'";
int result = statement.executeUpdate(query);
if ( result == 1 ){
JOptionPane.showMessageDialog(null,"Deletion Sucess",
"Deletion",JOptionPane.INFORMATION_MESSAGE);
for ( int count = 0; count < employeeList.size(); count++ ){
Staff temp = (Staff)employeeList.get(count);
if ( temp.getID().equalsIgnoreCase(staffID.trim())){
studentList.remove(count);
}
}
return true;
}else{
JOptionPane.showMessageDialog(null,"Deletion Failed",
"Deletion",JOptionPane.INFORMATION_MESSAGE);
return false;}
}catch(SQLException sqlex){
sqlex.printStackTrace();
return false;
}
}
public boolean delStudent(String studentID){
try{
Statement statement = connection.createStatement();
String query = "DELETE FROM Student WHERE studentid ='" + studentID + "'";
int result = statement.executeUpdate(query);
if ( result == 1 ){
JOptionPane.showMessageDialog(null,"Deletion Sucess",
"Deletion",JOptionPane.INFORMATION_MESSAGE);
///delete mark;
for ( int count = 0; count < studentList.size(); count++ ){
Student temp = (Student)studentList.get(count);
if ( temp.getID().equalsIgnoreCase(studentID.trim())){
studentList.remove(count);
}
}
return true;
}else{
JOptionPane.showMessageDialog(null,"Deletion Failed",
"Deletion",JOptionPane.INFORMATION_MESSAGE);
return false;
}
}catch(SQLException sqlex){
sqlex.printStackTrace();
JOptionPane.showMessageDialog(null,sqlex.getMessage());
return false;
}
}
public boolean delClassroom(String classroomid){
try{
Statement statement = connection.createStatement();
String query = "DELETE FROM Classroom WHERE classroomID = '" + classroomid + "'";
int result = statement.executeUpdate(query);
if (result == 1){
JOptionPane.showMessageDialog(null, "Deletion Success", "Insertion", JOptionPane.INFORMATION_MESSAGE);
for ( int count = 0; count < classroomList.size(); count++ ){
Classroom temp = (Classroom)classroomList.get(count);
if ( temp.getClassroomID().equalsIgnoreCase(classroomid.trim())){
studentList.remove(count);
}
}
}else{
JOptionPane.showMessageDialog(null, "Deletion Failed", "Deletion", JOptionPane.INFORMATION_MESSAGE);
return false;
}
}catch(SQLException sqlex){
sqlex.printStackTrace();
JOptionPane.showMessageDialog(null, sqlex.getMessage());
return false;
}
return true;
}
private void startConnection(){
try {
String url = "jdbc
dbc
op";
String user = "oop";
String password = "abc123";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
connection = DriverManager.getConnection(url,user,password);
System.out.println("Connection Successful");
getClassroomData();
getStudentData();
getEmployeeData();
}
catch (ClassNotFoundException cnfex) {
cnfex.printStackTrace();
JOptionPane.showMessageDialog(null,"Database Connection Error",
getUniversityName(),JOptionPane.ERROR_MESSAGE );
System.exit(1);
}
catch (SQLException sqlex) {
sqlex.printStackTrace();
JOptionPane.showMessageDialog(null,"Database Connection Error",
getUniversityName(),JOptionPane.ERROR_MESSAGE );
System.exit(1);
}
catch (Exception ex) {
ex.printStackTrace();
JOptionPane.showMessageDialog(null,"Database Connection Error",
getUniversityName(),JOptionPane.ERROR_MESSAGE );
System.exit(1);
}
}
continue...