public int deleteName
(String name
){ int myResult = -1;
int totalRow = 0;
char choix = 'i';
try {
//Don't commit before the user comfirm !
databaseConnection.setAutoCommit(false);
SQLRequest_client = "SELECT id FROM client WHERE nom = ?";
myRequest_client = databaseConnection.prepareStatement(SQLRequest_client);
myRequest_client.setString(1,name);
myResultset = myRequest_client.executeQuery();
while (myResultset.next()){
idList.add(myResultset.getBigDecimal(1));
//System.out.println(""+myResultset.getBigDecimal(1));
}
myRequest_client.close();
myRequest_client = null;
if (idList.size() > 0){
//Because of the keys, I must delete all the sejours of the client before delete the client himself
SQLRequest_sejour = "DELETE FROM sejour WHERE idclient = ?";
myRequest_sejour = databaseConnection.prepareStatement(SQLRequest_sejour);
for (int i = 0; i < idList.size(); i++){
myRequest_sejour.
setBigDecimal(1,
(BigDecimal)idList.
get(i
));
myResult = myRequest_sejour.executeUpdate();
totalRow += myResult;
}
myRequest_sejour.close();
myRequest_sejour = null;
System.
out.
println("Number of row to delete into table sejour : " + totalRow
);
//Delete the client
SQLRequest_client2 = "DELETE FROM client WERE nom = ?";
myRequest_client2 = databaseConnection.prepareStatement(SQLRequest_client2);
myRequest_client2.setString(1,name);
//***** Le problème est ici **************
myResult = myRequest_client2.executeUpdate();
//**********************************
totalRow += myResult;
myRequest_client2.close();
myRequest_client2 = null;
System.
out.
println ("You will delete " + totalRow +
" Rows, are you sure ?" );
choix = Keyboard.readChar();
if (choix == 'y'){
databaseConnection.commit();
}else{
databaseConnection.rollback();
totalRow = 0;
}
}
databaseConnection.setAutoCommit(true);
}
try {
databaseConnection.rollback();
totalRow = 0;
}
System.
out.
println ("SQL Error: " + e
);
}
System.
out.
println ("Other Exception: " + e
);
}
return totalRow;
}