Check in JDBC that a request execute correctly
I am trying to execute dynamic SQL in a Servlet using JDBC, I need to check either the user request was executed correctly or not.
I am ussing the Execute command wich return a boolean: TRUE indicates the result is a ResultSet and FALSE indicates it has the int value which denotes number of rows affected by the query. And this method throws SQLException - if a database access error occurs.
So I don't see any mean to tell the user either his request was executed correcty or not (because of a bad syntax)
If there was a database error, you will get an SQLException.
If there is no database error, but the results are still "wrong" for your application, you have to add some extra checks in your own code (such as inspecting the number of affected rows, or running some additional queries). Maybe more constraints are also an option.
Once you have determined if there was a problem, you can inform your user about it. You will have to break it down to him in terms that he can understand (because he has no idea about how your database works), how it affects him, and what he can do about it (such as retrying it later, double-checking his input data, or contacting user support). There is nothing JDBC can do to help you with that.
If there was a problem, you probably also want to log the incident for future reference.
链接地址: http://www.djcxy.com/p/74412.html上一篇: 在Apache Camel中访问存储过程的多个结果集
下一篇: 在JDBC中检查请求是否正确执行