user2079064
user2079064

Reputation: 9

SQLite database directory in intellij idea

I am trying some simple android codes in intellij IDEA. I have an .db SQLite DataBase of words. But I Dont know witch Directory of project I have to Paste the DB file I Opened this DB like this :

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

and used like this : try {

                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();
            }

cheers,

Upvotes: 0

Views: 1687

Answers (1)

hackp0int
hackp0int

Reputation: 4161

Usually you leave it to a Framework to do... but in your case it's pretty simple

You /assets/

Create it like so...

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();
   }

Upvotes: 1

Related Questions