简体   繁体   中英

Fix SQL error incompatible types: capture#1 of ? cannot be converted to int

I have a SQL query to query an Ignite cache database. But select count(column_Name) gives following compilation error. incompatible types: capture#1 of? cannot be converted to int

here is my code.

private static final String sql = "Select count(_val) from Annotations where  orderId = ? and timestamp <= ? and timestamp >= ? ";
SqlFieldsQuery sqlQ = new SqlFieldsQuery(sql).setArgs(id, t1, t2);
int count = 0;
        try (QueryCursor<List<?>> cursor = cache.query(sqlQ)) {
            for (List<?> row : cursor) {
                
                    count = (int) row.get(0);
                
            }

Instead of the for loop, I tried count = (int) cursor.getAll().get(0).get(0); But that also didn't work. Anyone have an idea what's happening here. Thank You.

Have you tried replacing ? with actual type?

    try (QueryCursor<List<Integer>> cursor = cache.query(sqlQ)) {
        for (List<Integer> row : cursor)                
                count = row.get(0);
            
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM