android 访问设备上现有的sqlite数据库
我正在为 iconia 选项卡(android 3.0)编写一个应用程序。在此应用程序中,我想访问已存在的 sqlite 数据库。在模拟器中它运行良好,但在设备上似乎我找不到应该放置数据库的正确文件夹。我对设备进行了root。我想也许如果我在程序中创建一个数据库,我可能会看到它的位置,但当我搜索它时,结果是它不存在。
数据库的构造函数:
public CustomSQLiteOpenHelper(Context context)
{
super(context, "blub.db", null, 1);
}
访问数据库:
public void showTestValues(){
ArrayList<Object> rowArray = new ArrayList<Object>();
Cursor cursor;
Log.d("myLog", "showTestValues");
try
{
// this is a database call that creates a "cursor" object.
// the cursor object store the information collected from the
// database and is used to iterate through the data.
cursor = db.rawQuery("SELECT * FROM artikel ", null);
// move the pointer to position zero in the cursor.
cursor.moveToFirst();
// if there is data available after the cursor's pointer, add
// it to the ArrayList that will be returned by the method.
if (!cursor.isAfterLast())
{
do
{
rowArray.add(cursor.getString(0));
Log.d("myLog", cursor.getString(0));
}
while (cursor.moveToNext());
}
// let java know that you are through with the cursor.
cursor.close();
}
catch (SQLException e)
{
Log.e("DB ERROR", e.toString());
e.printStackTrace();
}
}
错误代码:
05-23 15:05:59.220: INFO/SqliteDatabaseCpp(7217): sqlite returned: error code = 1, msg = no such table: artikel, db=/data/data/com.example.inspiratedshopping/databases/blub.db
我尝试使用 eclipse 中的 adb 文件资源管理器将数据库推送到 data/data/com.example.inspiratedshopping/databases 方向 - 我收到错误:
“无法推送选择:没有这样的文件或目录”,
因此我在设备上使用了文件专家资源管理器,并且可以放置数据库。但你会看到上面的错误。
有人有这方面的经验吗? 提前致谢!!!
I am programming an application for the iconia tab (android 3.0). In this application I want to access a sqlite database that is already existing. In the emulator it worked well, but on the device it seems i can't find the right folder where I should place the database. I rooted the device. I thought maybe if i create a database in the program I might see where it is positioned but when I am searching for it, the result is that it's nowhere.
Constructor of the database:
public CustomSQLiteOpenHelper(Context context)
{
super(context, "blub.db", null, 1);
}
accessing the database:
public void showTestValues(){
ArrayList<Object> rowArray = new ArrayList<Object>();
Cursor cursor;
Log.d("myLog", "showTestValues");
try
{
// this is a database call that creates a "cursor" object.
// the cursor object store the information collected from the
// database and is used to iterate through the data.
cursor = db.rawQuery("SELECT * FROM artikel ", null);
// move the pointer to position zero in the cursor.
cursor.moveToFirst();
// if there is data available after the cursor's pointer, add
// it to the ArrayList that will be returned by the method.
if (!cursor.isAfterLast())
{
do
{
rowArray.add(cursor.getString(0));
Log.d("myLog", cursor.getString(0));
}
while (cursor.moveToNext());
}
// let java know that you are through with the cursor.
cursor.close();
}
catch (SQLException e)
{
Log.e("DB ERROR", e.toString());
e.printStackTrace();
}
}
Error code:
05-23 15:05:59.220: INFO/SqliteDatabaseCpp(7217): sqlite returned: error code = 1, msg = no such table: artikel, db=/data/data/com.example.inspiratedshopping/databases/blub.db
I tried to push the database on the direction data/data/com.example.inspiratedshopping/databases with the adb file explorer in eclipse - i get the error:
"Failed to push selection: No such file or directory"
so i used the file expert explorer on the device and it was possible to place the database. But you see the error up there.
Anyone has experience with that?
Thanks in advance!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看看这篇博文。如果您有一个已经存在的数据库,据我所知,需要将其包含在 Assets 文件夹中。
http://www.reigndesign.com/博客/在android应用程序中使用您自己的sqlite数据库/
Have a gander at this blog post. If you have a database that is already existing, it would need to be included, as far as I know, in the Assets folder.
http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/