我如何运行在Android这个SQLite的查询:从表中选择其中x =东西,Y =东西 [英] How do I run this SQLite query on Android: select X from TABLE where X=something AND Y=something

查看:123
本文介绍了我如何运行在Android这个SQLite的查询:从表中选择其中x =东西,Y =东西的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的表apTable:

This is my table apTable:

db.execSQL("CREATE TABLE "+apTable+"
 ("
+idAP+" TEXT PRIMARY KEY , "
+ssID+" TEXT, " 
+testAPid+" INTEGER NOT NULL ,FOREIGN KEY ("+testAPid+") REFERENCES "+testsTable+" ("+colTestID+") ON DELETE CASCADE);");

我想进行查询,这将使我的IDAP行,其中,IDAP等于给定值和那里的外键等于另一个给定值。

I want to make a query that will give me the idAP rows where, idAP equals a given value and where the foreign key equals another given value.

我做的这样,但它不工作:

I'm doing it like this, but it isn't working:

 public String CheckAP(String BSSID, String Teste)
 {
     SQLiteDatabase db=this.getReadableDatabase();
     String[] params=new String[]{BSSID, Teste};
     Cursor c=db.rawQuery("SELECT "+idAP+" FROM "+apTable+" WHERE "+idAP+"="+BSSID+" AND "+testAPid+"="+Teste, null);           
     c.moveToFirst();
     int index= c.getColumnIndex(idAP);
    return c.getString(index);    
}

有什么问题吗?

推荐答案

请参阅本。

使用数据库openhelper。

Use a database openhelper.

http://www.screaming-penguin.com/node/7742

和使用它来检查是否已创建数据库。

And use this to check if you have created your database.

http://androidblogger.blogspot.com/2009/06/tutorial-how-to-access-android-database.html

这篇关于我如何运行在Android这个SQLite的查询:从表中选择其中x =东西,Y =东西的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆