Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android访问设备上现有的sqlite数据库_Android_Sql_Sqlite - Fatal编程技术网

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

android访问设备上现有的sqlite数据库,android,sql,sqlite,Android,Sql,Sqlite,我正在为iconia标签(android 3.0)编写一个应用程序。在这个应用程序中,我想访问一个已经存在的sqlite数据库。在emulator中,它工作得很好,但在设备上,我似乎找不到应该放置数据库的正确文件夹。我在设备上安装了根。我想,如果我在程序中创建一个数据库,我可能会看到它的位置,但当我搜索它时,结果是它不存在 数据库的构造函数: public CustomSQLiteOpenHelper(Context context) {

我正在为iconia标签(android 3.0)编写一个应用程序。在这个应用程序中,我想访问一个已经存在的sqlite数据库。在emulator中,它工作得很好,但在设备上,我似乎找不到应该放置数据库的正确文件夹。我在设备上安装了根。我想,如果我在程序中创建一个数据库,我可能会看到它的位置,但当我搜索它时,结果是它不存在

数据库的构造函数:

        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();
            }
        }
我试图用eclipse中的adb文件资源管理器将数据库推到data/data/com.example.inspiratedshopping/databases方向-我得到错误:

“推送选择失败:没有这样的文件或目录”

因此,我在设备上使用了文件专家浏览器,可以放置数据库。但是你看到上面的错误了

有人有这方面的经验吗?
提前感谢

看看这篇博文。如果您有一个已经存在的数据库,就我所知,它需要包括在Assets文件夹中


您可能没有创建数据库的代码,如果不存在,您应该创建路径。无论如何,有两次/数据/数据看起来很陌生。谢谢你的回答。不,我没有创建数据库的代码,因为它已经存在,我只想读取它。你觉得什么不一样?我在所有教程中都发现数据库存储在/data/data/your.applications.package/databases中。您会发现,即使在根设备上,访问由另一个应用程序创建的数据库也非常困难,除非它是您自己的应用程序,它与尝试访问它的应用程序共享用户ID,或者使数据库文件世界可访问并将其放置在已知位置。如果是根目录,这是可能的,但很困难,因为您必须从独立的可执行文件(而不是java或jni代码)中执行棘手的部分。我在桌面系统上自己创建了数据库,因为它需要一些计算时间。你认为我应该把数据库放在远程系统上,用RMI之类的东西获取数据吗?难道没有更智能的解决方案吗?为什么它只在模拟器上工作,而不在设备上工作?正如我在StackOverflow上阅读的那篇文章和其他与此相关的文章一样,请特别注意,您似乎必须首先按照从资产复制数据库到另一个位置的步骤进行操作。我明白了,对于大于1 mb的数据库,这可能是不可能的。。。我的大约有20 MB,为什么需要将数据库从/assets/文件夹复制到另一个位置?为什么我不能直接从/assets/中的数据库中读取?
 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