我在 Android 中有一个静态 sqlite 数据库。函数接受 int 类型的输入并对数据库进行查询。输入值为 97,500 时它工作正常,但如果我输入更大的值,则会发生两种情况之一
- 如果输入为 98,000-99,500,则返回 null
- 如果输入大于 100,000,则返回错误数据
这是发生故障的功能:
Budget getBudget(int income,String name)
{
Budget B=null;
Log.d("DB", String.valueOf(income));
try{
SQLiteDatabase db=this.getReadableDatabase();
Cursor cur=db.rawQuery("SELECT * FROM "+BudgetTable+" WHERE "+Low+"<=? AND "+High+">=?", new String[]{String.valueOf(income),String.valueOf(income)});
Log.d("DB", String.valueOf(cur.getCount()));
if(cur.getCount()!=0)
{
Log.d("DB", "Cursor not empty");
cur.moveToFirst();
B=new Budget(0, income,cur.getInt(cur.getColumnIndex(MortgageRent)),cur.getInt(cur.getColumnIndex(Utilities)) ,
cur.getInt(cur.getColumnIndex(LightnPower)), cur.getInt(cur.getColumnIndex(PhonenInternet)),
cur.getInt(cur.getColumnIndex(HomeMaintenance)), cur.getInt(cur.getColumnIndex(HomeCleaning)),
cur.getInt(cur.getColumnIndex(Groceries)), cur.getInt(cur.getColumnIndex(Clothing)),0,
cur.getInt(cur.getColumnIndex(PersonalGrooming)), cur.getInt(cur.getColumnIndex(MedicalnPharmacy)),
cur.getInt(cur.getColumnIndex(HealthInsurance)), cur.getInt(cur.getColumnIndex(LifeInsurance)),
cur.getInt(cur.getColumnIndex(HomeInsurance)), cur.getInt(cur.getColumnIndex(Accounting)),
cur.getInt(cur.getColumnIndex(BankFees)), cur.getInt(cur.getColumnIndex(Fuel)),
cur.getInt(cur.getColumnIndex(ServicenRepairs)), cur.getInt(cur.getColumnIndex(GovernmentCharges)),
cur.getInt(cur.getColumnIndex(CarInsurance)),0, cur.getInt(cur.getColumnIndex(PublicTransport)),
cur.getInt(cur.getColumnIndex(Entertainment)), cur.getInt(cur.getColumnIndex(SportsnGym)),
cur.getInt(cur.getColumnIndex(EatOut)), cur.getInt(cur.getColumnIndex(Alcohol)),
cur.getInt(cur.getColumnIndex(Gifts)), cur.getInt(cur.getColumnIndex(Holidays)),
cur.getInt(cur.getColumnIndex(NewspapernMagazine)), cur.getInt(cur.getColumnIndex(Others)), 0, 0, name);
Log.d("DB", String.valueOf(cur.getInt(cur.getColumnIndex(IncomeLevel))));
cur.close();
db.close();
}
}catch(Exception ex)
{
Log.d("DB", ex.getMessage());
}
return B;
}
下面是数据库中数据的屏幕截图...我不知道为什么它不起作用。