Can we add a getColumn method to SQLException ?
West Farmer
guogangfan at gmail.com
Thu Jan 25 14:36:57 UTC 2024
Hi, JDBC experts!
I am just an ordinary Java developer. When I designed my Restful interface,
I defined the following response entities:
{
code: "the response code",
emsg: "the user friendly error message",
eproperty: "the property of the entity which causing the error "
}
For example, when the client code updates a user's email address through my
Restful interface, if the email address already exists, I want to return an
error like the following:
{
code: 400001,
emsg: "email address already taken",
eproperty: "email"
}
Typically, the database side defines uniqueness constraints for the
corresponding fields of the email.
However, I found that through the existing JDBC API, it seems not easy to
parse the corresponding field names from the errors returned by the
database, especially considering the need to support different types of
databases.
Similar functions have been implemented in the JDBC drivers of some
databases, such as postgresql. Its PSQLException class inherits
java.sql.SQLException, we can get a ServerErrorMessage, and this class
provides the getColumn method to get the field name that caused the error.
Can we add a public Optional<String> getOptionalCausingColumn method to
SQLException?
Please forgive me, if I am asking at wrong place.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/jdbc-spec-discuss/attachments/20240125/31628a5c/attachment.htm>
More information about the jdbc-spec-discuss
mailing list