Skip to content
Advertisement

How to call a DB2 stored procedure passing a List as param?

Java version: Java1.8
JDBC: db2jcc4-11.1.1.1
Ant1.7
Websphere8.5

I am upgrading a service to allow for passing an array of currency codes (AA, BB, CC, DD) into a stored procedure. The NSP work has been completed and verified. Here is my code below.

Mapper

<!-- Call XXXXXXX- InputArray -->
    <select id="addOrRemoveDataList" statementType="CALLABLE"
        parameterType="globalTradeAwayParams">
        {CALL ${dbPackageName}.XXXXXXX
            (#{param.ownerId, mode=IN, jdbcType=INTEGER},
            #{param.actionInd, mode=IN, jdbcType=CHAR},
            #{param.addOrRemoveElementsCount, mode=IN, jdbcType=INTEGER},
            #{param.addOrRemoveList, jdbcType=ARRAY, mode=IN, jdbcTypeName=VARCHAR, typeHandler=com.pseuplex.core.db.handlers.StringHandler})}
    </select>

StringHandler

public class StringHandler implements TypeHandler<List<String>> {
    
    // Adding logger to StringHandler
    private static Logger log = Logger.getLogger(StringHandler.class);
    
    @Override
    public void setParameter(PreparedStatement arg0, int arg1, List<String> arg2, JdbcType arg3) throws SQLException {
        // TODO Auto-generated method stub
        log.info("Prepared statement: " + arg0.toString());
        log.info("Arg1: " + arg1);
        log.info("Object: " + arg2);
        log.info("JDBC Type: " + arg3);
        
        // TODO Auto-generated method stub
        Array string = null;
        int index = 0;
        String[] stringArray;
        
        if (arg2 == null)
            stringArray = new String[0];
        else {

            stringArray = new String[arg2.size()];

            for (String i : arg2) {

                stringArray[index] = i;
                index++;
            }
        }

        Connection con = arg0.getConnection();
        
        // ERROR THROWN HERE
        string = con.createArrayOf("VARCHAR", stringArray);
        
        arg0.setArray(arg1, string);
        
    }

    @Override
    public List<String> getResult(ResultSet arg0, String arg1)
            throws SQLException {
        // TODO Auto-generated method stub
        return new ArrayList<String>();
    }

    @Override
    public List<String> getResult(ResultSet arg0, int arg1) throws SQLException {
        // TODO Auto-generated method stub
        return new ArrayList<String>();
    }

    @Override
    public List<String> getResult(CallableStatement arg0, int arg1)
            throws SQLException {
        // TODO Auto-generated method stub
        return new ArrayList<String>();
    }

}

During runtime, I am getting this error when submitting the change to my database:

FATAL com.pseuplex.j2ee.ExceptionFilter – java/sql/Connection.createArrayOf(Ljava/lang/String;[Ljava/lang/Object;)Ljava/sql/Array; java.lang.AbstractMethodError: java/sql/Connection.createArrayOf(Ljava/lang/String;[Ljava/lang/Object;)Ljava/sql/Array;

I have checked pages of stack overflow questions similar to this one, but none of the solutions have led me to a solution. Any help would be greatly appreciated.

Advertisement

Answer

Just following up on this for future reference, I found my solution to the AbstractMethodError. I was using an old version of dbcp and ended up having to upgrade to commons-dbcp2 as well as commons-pool2.

After the upgrade, I simply changed my datasource to target dbcp2 and everything worked fine.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement