从另一个类Android应用程序调用SQL [英] call sql from another class for android app
问题描述
喜
我已经创建了我的应用程序的数据库,我已经添加的项目使用从数据库类方法的数据库。我遇到一个问题,做当我尝试执行中的其他类(app.java)一个SQL查询,我需要引用一个数据库和多数民众赞成在有问题!IM
Hi I have created a database for my application and i have added items to the database using methods from the database class. I am encountering a problem do when i try to execute a sql query in the other class(app.java), i need to reference a database and thats where im having the problem!
这是SQL查询即时试图执行(以database.java)
this is the sql query im trying to execute(in database.java)
public void getData(SQLiteDatabase db, String data){
String sql =
"SELECT permissions FROM genres WHERE name = "+data+";";
db.execSQL(sql);
}
这就是我如何调用它(在app.java)
and this is how i am calling it(in app.java)
appData.getData(db, chosenGenre);
我只是不没有做什么,在 appData.getPermissions(DB,chosenGenre)提出了DB的一部分;
有谁知道如何做到这一点?
谢谢
Does anyone know how to do this? Thanks
推荐答案
您通常会使用 SQLiteOpenHelper
来创建数据库文件(如有必要),并获得 SQLiteDatabase
这是用来访问实际的数据库对象(在磁盘上由SQLite的读取文件)。
You would typically use a SQLiteOpenHelper
to create the database files (if necessary) and obtain a SQLiteDatabase
object which is used to access the actual database (files on disk read by SQLite).
的http://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html
下面是一个不错的教程
http://www.anotherandroidblog.com/2010 / 08/04 / Android的数据库教程/ 2 /
这篇关于从另一个类Android应用程序调用SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!