DB2 database; stored procedure, upon null result set, returns 
java.lang.NullPointerException
--------------------------------------------------------------------------------------------

         Key: IBATIS-202
         URL: http://issues.apache.org/jira/browse/IBATIS-202
     Project: iBatis for Java
        Type: Improvement
  Components: DAO  
    Versions: 2.1.5    
 Environment: DB2 database, db2jcc.jar driver, jdk1.4
    Reporter: Carl Gulovsen
    Priority: Minor


Hello:  First time post, please excuse any ethic violations.

I am calling a stored procedure which should return a result set within a DB2 
database.  The issue I am having is the procedure checks IN parameters, checks 
to see if your userID can even run the SP, etc.   Within my unit tests I 
trigger these checks and the SP sets the error return code, the SQLSTATE, 
SQLCODE, and an output message.  Because of the errors, the Cursor for the 
result set is never created.   The process throws a  NullPointerException when 
attempting to process the result set.

SqlExecutor.executeQueryProcedure() is called:

  public void executeQueryProcedure(RequestScope request, Connection conn, 
String sql, Object[] parameters,
                                    int skipResults, int maxResults, 
RowHandlerCallback callback)
      throws SQLException {
...

      cs.execute();
      rs = cs.getResultSet();

/* here the rs is null */
...
     handleResults(request, rs, skipResults, maxResults, callback);  --> 
steping into handleResults

  private void handleResults(RequestScope request, ResultSet rs, int 
skipResults, int maxResults, RowHandlerCallback callback) throws SQLException {
    try {

      request.setResultSet(rs);
      ResultMap resultMap = request.getResultMap(); 
      if (resultMap != null) {
        // Skip Results
        if (rs.getType() != ResultSet.TYPE_FORWARD_ONLY) {
....
Here the rs throws the null pointer.

Would it be possible for you to add:
  private void handleResults(RequestScope request, ResultSet rs, int 
skipResults, int maxResults, RowHandlerCallback callback) throws SQLException {
    try {

      request.setResultSet(rs);
      ResultMap resultMap = request.getResultMap(); 
      if (rs != null && resultMap != null) {
        // Skip Results
        if (rs.getType() != ResultSet.TYPE_FORWARD_ONLY) {
.
Here you would check to see if there is a null result set before process.  I 
believe it to be relatively common that a stored procedure would not return a 
result set when errors occur.

Thank you.
Carl



-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira

Reply via email to