android 访问设备上现有的sqlite数据库

发布于 2024-11-09 09:02:43 字数 2165 浏览 0 评论 0原文

我正在为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

享受孤独 2024-11-16 09:02:43

看看这篇博文。如果您有一个已经存在的数据库,据我所知,需要将其包含在 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/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文