使用子字符串sqlite查询数据时,字符串索引超出绑定异常

时间:2013-08-03 14:19:11

标签: android sqlite cursor substring

我想通过使用下面的语句查询当前年度总价的总和,但总是出错:java.lang.StringIndexOutOfBoundException:length = 8,index = 2013 .. 它有什么我应该改变代码吗?

public double SumPriceYear(){

int yyyy = Integer.valueOf(getThisYear());
Cursor sum = ourDatabase.rawQuery("SELECT SUM( " + Pro_Price + " ) FROM "+ TABLE_NAME + " Where " + Pro_Date + " LIKE '%" + yyyy + "%' ", null);

if(sum.moveToFirst())
{
    return sum.getDouble(0);
}

return sum.getDouble(0);

}

0 个答案:

没有答案