0

I have project which goes like this in the DDMS path

packagename->FolderA->FolderB->DatabaseFile.db

now there are many tables in this db file.I want to insert to a MyTable table. So can anyone help me form the correct uri?

content://packagename/ then?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
vishine
  • 63
  • 8

3 Answers3

1

I am assuming that your whole folder structure resides in removable sd card

if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
{
File directory=Environment.getExternalStorageDirectory();
File myFolder=new File(directory+"/FolderA/FolderB/DatabaseFile.db");
 }
foxt7ot
  • 2,465
  • 1
  • 19
  • 30
0
public static void copyDataBase(Context mActivity) throws IOException {
  • InputStream myInput = new FileInputStream(new File("/data/data/" + mActivity.getPackageName() + "/databases/" + "xxxx.sqlite"));

        File files = new File("/sdcard/files/");
        files.mkdirs();
        String outFileName = "/sdcard/files/xxxx.sqlite";
        OutputStream myOutput = new FileOutputStream(outFileName);
        byte[] buffer = new byte[1024];
        int bufferLength;
        while ((bufferLength = myInput.read(buffer)) > 0) {
            myOutput.write(buffer, 0, bufferLength);
        }
        myOutput.flush();
        myOutput.close();
        myInput.close();
    }
    

above function copy from ur data->data database to sdcard.

InputStream myInput = new FileInputStream(new File("/data/data/" + mActivity.getPackageName() + "/databases/" + "xxxx.sqlite"));*

this line is used to get database path.

I hope its helpful to you.

dipali
  • 10,966
  • 5
  • 25
  • 51
0

You just create the database like this

SQLiteDatabase db=openOrCreateDatabase("MYDB",MODE_PRIVATE,null);

To insert into the table

db.execSQL("create table if not exists mytable (fname varchar,lname varchar);");
db.execSQL("insert into mytable values('my first name','my last name')";);

To see the database goto

DDMS->data->data->com.example.package->databases

Try it..

Lal
  • 14,726
  • 4
  • 45
  • 70