I was wondering how would I be able to show SQL errors generated during update, delete, select * etc in JSF.
Any help would be appreciated.
I was wondering how would I be able to show SQL errors generated during update, delete, select * etc in JSF.
Any help would be appreciated.
You have three options:
Let the exception bubble up (either declare your action methods throws SQLException
, or wrap them in RuntimeException
catch
the SQLException
and add it as a JSF message, which is more readable. The format is up to you.
String msg = obtainFormattedMessageFromException(exception);
FacesMessage facesMessage =
new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, msg);
FacesContext.getCurrentInstance().addMessage(null, facesMessage);
Don't show them (best option). These exceptions would confuse the user. Instead, log them (using log4j, commons-logging, or whatever) to a log file, which you will be able to read later. Show only a generic message to the user that something went wrong.