如何在编写存储过程或从java访问存储过程时处理错误条件?使用java存储过程错误处理
4
A
回答
0
如果某些操作失败,存储过程应返回错误代码,但如果存储过程本身失败,则只能选择捕获SQLException。
0
try {
CallableStatement stmt=con.prepareCall("{call insertR(?,?)}");
stmt.setInt(1,1011);
stmt.setString(2,"Amit");
stmt.execute();
} catch(SQLException e) {
e.printStack();
}
+0
@ user2156381关于如何处理SQLexception – 2015-03-12 17:34:36
0
this piece of code is taken from oracle [docs][1] to answer.
public void
createProcedureShowSuppliers()
throws SQLException {
String createProcedure = null;
String queryDrop =
"DROP PROCEDURE IF EXISTS SHOW_SUPPLIERS";
createProcedure =
"create procedure SHOW_SUPPLIERS() " +
"begin " +
"select SUPPLIERS.SUP_NAME, " +
"COFFEES.COF_NAME " +
"from SUPPLIERS, COFFEES " +
"where SUPPLIERS.SUP_ID = " +
"COFFEES.SUP_ID " +
"order by SUP_NAME; " +
"end";
Statement stmt = null;
Statement stmtDrop = null;
try {
System.out.println("Calling DROP PROCEDURE");
stmtDrop = con.createStatement();
stmtDrop.execute(queryDrop);
} catch (SQLException e) {
JDBCTutorialUtilities.printSQLException(e);
} finally {
if (stmtDrop != null)
{
stmtDrop.close();
}
}
try {
stmt = con.createStatement();
stmt.executeUpdate(createProcedure);
} catch (SQLException e) {
JDBCTutorialUtilities.printSQLException(e);
} finally {
if (stmt != null) { stmt.close(); }
}
}
[1]: https://docs.oracle.com/javase/tutorial/jdbc/basics/storedprocedures.html
+0
请包括您参考的代码的一些解释,否则您的答案不是您的答案 – jhhoff02 2017-07-05 18:45:47
相关问题
- 1. SQL存储过程和错误处理
- 2. MySQL存储过程错误处理
- 3. 存储过程中的错误处理
- 4. 存储过程和错误处理
- 5. 存储过程中的错误处理
- 6. 存储过程与用户定义的错误处理功能
- 7. extjs存储错误处理
- 8. MariaDB存储过程错误处理程序
- 9. 存储过程继续处理程序错误
- 10. 从存储过程处理程序中访问错误堆栈
- 11. 使用存储过程给错误
- 12. 错误使用存储过程
- 13. 如何处理基本MySQL存储过程中的错误?
- 14. SQL Server存储过程中的错误处理
- 15. MYSQL 5.5嵌套存储过程错误处理
- 16. ASP.NET - 数据库存储过程中的错误处理
- 17. 存储过程错误处理当参数被忽略
- 18. 存储过程中的多重错误处理
- 19. Oracle存储过程中的错误处理
- 20. Java错误处理程序
- 21. Java处理程序错误
- 22. 错误处理Java程序
- 23. 执行多个存储过程导致错误[使用事务处理]
- 24. SQL Server:存储过程存储错误
- 25. 处理Oracle过程错误
- 26. 存储过程InvalidCastException错误
- 27. ADO.NET存储过程错误
- 28. SQL存储过程错误
- 29. 错误从存储过程
- 30. 存储过程有错误
Thanks..How处理返回错误代码? – user2156381 2014-11-06 06:09:54