sqlite数据库异常汇总信息

来源:互联网 发布:展uv软件 编辑:程序博客网 时间:2024/05/16 08:36

1.java.lang.IllegalArgumentException: the bind value at index 1(数字 从1开始 1代表条件中的第一个字段 ) is null

当预处理查询数据库时 where 子句里的条件参数值有null时将报该错误

如 Cursor cursor=db.rawQuery("select * from user where name = ?" ,new String[]{null});

sql查询表中某个字段为null的记录时应该如下查询

Cursor cursor=db.rawQuery("select * from user where name is null" ,null);

sql查询表中某个字段不为null的记录时应该如下查询

Cursor cursor=db.rawQuery("select * from user where name is not null" ,null);

如果要查询的字段为int型  那木null代表0  即上面这条语句如果name为int型  则查询表中name不为0的记录

查询时条件语句中使用了is null 或 not null 时 如果表中某字段设置了索引  则查询时将不会使用索引  这时如果想使用索引则需变更sql中的where子句 如下

Cursor cursor=db.rawQuery("select * from user where name = ?" ,new String[]{"0"});  //name为int型

Cursor cursor=db.rawQuery("select * from user where name = ?" ,new String[]{"-100"}); //创建表时为name设置一个默认值(如-100)

0 0
原创粉丝点击