I am have downloaded my assignment recently and before going ahead with design / implementation , I thought of creating a sample client and invoke the different methods on Data class.
I am getting the following exception when I tried to create a new record in the database and followed by trying to modify
and delete
A new record is added successfully to the database
Exception while modifying the record in the database Attempt to create a duplicate key by modification
The record is deleted successfully in the database
The question is how the Data class does not let me modify the record but let me delete it.
My code is as follows
String[] addData = { "BB001" ,
"SFO" ,
"LHR" ,
"SpeedyAir ",
"2000 " ,
"Mon" ,
"11:20" ,
"11h65m " ,
"24 "
};
for ( int j = 0; j < addData.length; j++ ) {
int fieldLen = addData[j].length();
System.out.println("Field Value = "+addData[j]);
System.out.println("Field length = "+fieldLen);
}
try {
db.add(addData);
System.out.println("A new record is added successfully to the database");
} catch(DatabaseException dbe)
{
System.out.println("Exception while adding the record to the database "+dbe.getMessage());
}
// Create a DataInfo object
String[] modifyData = { "BB001" ,
"SEA" ,
"SFO" ,
"EVA ",
"2000 " ,
"Mon" ,
"11:20" ,
"11h65m " ,
"26 "
};
DataInfo dataRecord = new DataInfo(count, description, modifyData);
// This method updates the record specified by the record number
// Field in the DataInfo argument. The fields are all modified
// to reflect the values in that argument. If the key field
// specified in the argument matches any record other than the
// one indicated by the record number of the argument, then a
// RuntimeException is thrown.
try {
db.modify(dataRecord);
System.out.println("The record is modified successfully in the database");
} catch(DatabaseException dbe)
{
System.out.println("Exception while modifying the record in the database "+dbe.getMessage());
}
// This method deletes the record referred to by the record
// number in the DataInfo argument.
// Create a DataInfo object
String[] deleteData = { "BB001" ,
"SFO" ,
"LHR" ,
"SpeedyAir ",
"2000 " ,
"Mon" ,
"11:20" ,
"11h65m " ,
"26 "
};
dataRecord = new DataInfo(count, description, deleteData);
try {
db.delete(dataRecord);
System.out.println("The record is deleted successfully in the database");
} catch(DatabaseException dbe)
{
System.out.println("Exception while deleting the record to the database "+dbe.getMessage());
}