执行SQL SQLite中对Android SDK [英] Executing SQL in SQLite on the Android SDK
问题描述
所以,我最近完成本教程,它的伟大工程,但我m是一点点卡在从我的数据库中读取数据。
So I've recently completed this tutorial and it works great, but I'm a little stuck on reading the data from my database.
我现在正在从数据库文件读取的感谢 Orsol 通过使用的本教程但我正在寻找我可以调用一个方法,该方法将返回我一个给定的字段的值。或至少一种方法,它可以让我执行SQL。
I'm now reading from the database file thanks to Orsol by using this tutorial but I'm looking now for a method I can call which will return me the values of a given field. Or at least a method that let's me execute SQL.
我最接近的是通过调用这样的:
The closest I have is by calling this:
public List<String> SelectAll()
{
List<String> list = new ArrayList<String>();
Cursor cursor = myDataBase.rawQuery("SELECT * FROM androidtable", null);
if (cursor.moveToFirst())
{
do
{
list.add(cursor.getString(0));
}
while (cursor.moveToNext());
}
if (cursor != null && !cursor.isClosed())
{
cursor.close();
}
return list;
}
但是,这只是抛出一个SQLiteException:
But this just throws a SQLiteException:
android.database.sqlite.SQLiteException:没有这样的表:androidtable:,编译时:SELECT * FROM androidtable
android.database.sqlite.SQLiteException: no such table: androidtable: , while compiling: SELECT * FROM androidtable
不过,我知道,我加载正确的文件(里面确实有此表),因为如果我更改目录路径或数据库名称,就会触发一个运行时错误。
I do however know that I am loading the correct file (which does have this table), as if I change the directory path or database name, it will fire a run time error.
谁能帮助?
感谢
推荐答案
如果你想使用你的应用程序之外创建的数据库,遵循的本教程
If you want to use database created outside of your application, follow this tutorial
这篇关于执行SQL SQLite中对Android SDK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!