Espen Schulstad
Espen Schulstad

Reputation: 2445

Spring NamedParameterJdbcTemplate + an array of Integers + Sybase

Sooo.. We found a bug and the stack pretty much looked like this

com.sybase.jdbc2.jdbc.SybSQLException: Class [java.lang.Integer not found. Check and make sure that the class has been installed, and an entry exists in Sysxtypes.

Then I thought, aaaaw, I just have to convert 'em into primitives.

int[] ids = ArrayUtils.toPrimitive(set.toArray(new Integer[set.size()]));

And then plugged the ids into the query

return namedParameterJdbcTemplate.query("select distinct id from Coffee where id in ( :ids )", Collections.singletonMap("ids", ids),
            new ParameterizedRowMapper<Integer>(){
            public Integer mapRow(ResultSet rs, int rowNum) throws SQLException {
                return rs.getInt("id");
            }
        });

Ok. Then I got this;

com.sybase.jdbc2.jdbc.SybSQLException: Class [I not found. Check and make sure that the class has been installed, and an entry exists in Sysxtypes.

I've never had any problems using either Integer nor int when I'm using the spring jdbc templates together with sybase. Any ideas?

Upvotes: 1

Views: 2626

Answers (1)

techarch
techarch

Reputation: 1141

instead of converting to primitives you need to make it a List rather than an array

instead of this

int[] ids = ArrayUtils.toPrimitive(set.toArray(new Integer[set.size()]));

you will need to do

Arrays.asList(ids)

Upvotes: 1

Related Questions