2012-03-25 39 views
-2

如何比较文本字段?我的专栏名称是Semester,其中有一个条目"V"在Sqlite的rawQuery方法中选择

Cursor result = 
    db.rawQuery("Select * from bookTable where Semester like 'V';",null); 
if(result.moveToFirst()) { 
    do { 
     if(name==null) { 
      name= result.getString(3); 
     } else { 
      name+= result.getString(3); 
    } while(result.moveToNext()); 
} else { 
    name="no value"; 
} 
return name; 

它在名称字符串中返回"no value"

回答

0

改变你的SQL查询:

Cursor result = 
db.rawQuery("Select * from bookTable where Semester = 'V'",null); 
+0

嘿感谢名单....我用了这个查询也..但我已经把一个分号它的结束..它的工作原理 – 2012-03-25 17:15:16

+0

@VIPULGOYAL我同意Nishant - 你是新来的stackoverflow,但你应该知道,为了让我们所有人从网站上获得最大的好处,问问者也应该注意。如果他解决了你的问题,你应该通过点击答案左边的空白检查来接受他的答案。也考虑upvoting他。 Upvote意味着你喜欢他答案的内容,并发现它们很有用。 – 2012-03-26 09:51:09

+1

我接受了他的回答! – 2012-03-26 16:02:17

0

如果您正在搜索具有给定名称的列,为什么您首先喜欢使用?使用普通的查询子句:

String tableName = "bookTable"; 
String whereClause = "Semester = ?"; 
String [] whereArgs = { "V" }; 
Cursor result = 
    db.query(tableName, null, whereClause, whereArgs, null, null, null);