android sqlite where,SELECT and WHERE in android (SQlite)

作者在数据库查询中遇到困难,试图同时过滤course_no和year,但发现只设置一个条件时代码可以运行。寻求如何在SQLite查询中处理多个字符串参数,以搜索course_no、semester和year。
摘要由CSDN通过智能技术生成

I want to search if there are exact course_no, semester ,and year value in the table.

I problem is that I can only filter course_no.

Cursor cursor = database.query(DatabaseHelper.TABLE_COURSE, CourseItemDataSource.allColumns, DatabaseHelper.KEY_COURSE_COURSE_NO + "=?", new String[] { notiItem.getCourseNo() }, null, null, null);

When I tried to add other filter it doesn't seems to work

[Edited] Sorry for being not informative, the problem is that when I pass the below code filter don't work. Note that notiItem.getCourseNo() and notiItem.getYear() is a String.

The following column in the table is a TEXT.

kwRvw.png

Cursor cursor = database.query(DatabaseHelper.TABLE_COURSE, CourseItemDataSource.allColumns, DatabaseHelper.KEY_COURSE_COURSE_NO + "=? AND "+DatabaseHelper.KEY_COURSE_YEAR+"=?", new String[] { notiItem.getCourseNo() ,notiItem.getYear()}, null, null, null);

This is code the method I tried

public CourseItem searchToCourse(NotificationItem notiItem){

/**Check if exact course_no, semester, year of notiItem exist in Course Table

* return null if not found

*

*/

String [] columns = new String[]{ "*"};

Cursor cursor = database.query(DatabaseHelper.TABLE_COURSE, CourseItemDataSource.allColumns, DatabaseHelper.KEY_COURSE_COURSE_NO + "=?", new String[] { notiItem.getCourseNo() }, null, null, null);

Log.i("DATA SOURCE", "AFTER QUERY ");

if (cursor != null) {

cursor.moveToFirst();

}

CourseItem courseItem = CourseItemDataSource.cursorToCourseItem(cursor);

return courseItem;

}

How can I search multiple column at a time??

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值