0

我正在intellij IDEA中尝试一些简单的android代码。 我有一个 .db SQLite 单词数据库。但我不知道项目的女巫目录我必须粘贴数据库文件我打开这个数据库是这样的:

 try {
            db=openOrCreateDatabase("data.db", 1,null);
        }
        catch (SQLException e)
        {
            Toast.makeText(getApplicationContext(),"ERR:"+e.getMessage(),Toast.LENGTH_LONG).show();
        }

并像这样使用:尝试{

                Cursor c;
                c = db.rawQuery("SELECT * FROM words WHERE en='"+ed.getText()+"'",null);
                v.append(c.getString(1));

            }
            catch (SQLException e)
            {
                Toast.makeText(getApplicationContext(),"ERR:"+e.getMessage(),Toast.LENGTH_LONG).show();
            }

干杯,

4

1 回答 1

1

通常你把它留给一个框架来做......但在你的情况下它很简单

你/资产/

像这样创建它...

As for DB_NAME = "yourfilename.db"
As for DB_NAME = "/data/data/" + context.getPackageName() + "/databases/";

    private void copyDataBase() throws IOException {
        InputStream mInput = mContext.getAssets().open(DB_NAME);
        String outFileName = DB_PATH + DB_NAME;
        OutputStream mOutput = new FileOutputStream(outFileName);
        byte[] mBuffer = new byte[1024];
        int mLength;
        while ((mLength = mInput.read(mBuffer)) > 0) {
            mOutput.write(mBuffer, 0, mLength);
        }
        mOutput.flush();
        mOutput.close();
        mInput.close();
   }
于 2013-02-16T19:21:30.690 回答