How can connect Sqlite2009 Pro Database and Android Application - android

I use Sqlite 2009 pro (Sqlite3 Management Studio) to create new database and insert data. My problem is how can I connect this database and Android application . When installing android application in phone, how can put database with application ?Please help me.

I'm assuming you are creating the database outside of Android. With this method you will simply copy the database to the applications folder (after installing your application), and then you should have it for use.
Create your database (lets call it mydb.db)
Install your base Android application (no db)
Open a command prompt, and cd into the directory with your mydb.db
Type adb push mydb.db /data/data/com.my.app.myapplication/databases
This copies your database that you created to the proper folder that your application should use for your databases (this is my folder structure on 2.2/2.3). Now in your java class, when you specify the database name, it should be mydb.db.
Generally you want to have all of your creation and update scripts built into your program. Using the Management Studio can be handy at first to design the db, but ultimately you'll want to use SQLiteOpenHelper to handle create/drop/update scripts. See this and this link for help with the SQLiteOpenHelper class.
NOTE: I just realized I am doing this on a rooted device, and you MAY not have access to copy to the /data/data/com.my.app/... folder. If you don't, then you might have to find some writable folder to put your database, and somehow access it. Or just use SQLiteOpenHelper :).

Related

Push db file to Databases folder in android

I wondered If it is possible to push db files into databases folder of an Android application either programatically or using any tool.
Thanks in advance!
Yes you can but not directly.
Typically a pre-built database would be included as an asset and copied to the databases folder for the package when the App is first run after installation.
If using this method then you should consider using SQLiteAssethelper, as using this simplifies the process.
In one of my App's I introduced a back-restore that backed-up the database and could restore from the downloads folder. If need be I can copy a database from elsewhere into the downloads folder and restore from that within the App. However obviously such a database has to have the correct structure/schema to not result in errors. So that is another way but would be at the user's discretion to do.
Obviously data/data//databases is protected so that imposes restrictions on "Pushing" data directly into the folder.

Access SQLite DB from IntelliJ for Android

How can I view the DB in IntelliJ to view its content and perform operations on it. Now I have created my tables etc but i have no idea what data is on the DB and I do not want to create queries in java to check it. seems like a slow workflow so ill wait til I know how to access the db that resides on the Android emulator im using.
Is it possible?
You can also use Stetho. A nice debugging tool from Facebook.
Just simple to use, initialize it in your Application class and access your sqlite and even shared preferences from Google Chrome's developer console.
You can create a database file outside of Android and use any tool to create and read it.
Then, you place it in the assets folder and setup your code to read the database from there instead of private app data. Caveat here is that a copy will be made from the assets folder to the app data, so any updates within the app won't be mirrored to the database file in the assets folder.
I believe you can access the DDMS window in Intellij/Android Studio and there is a Database Explorer there
see #alexsimo's answer.
Without root you cannot access your database on your device, unless the file is created with a+r permissions.
Since that is something that is unrelated to the issue, you can just search in plugin.jetbrains.com for sqlite and get a variety of plugins.

using an exported sqlite database in Android

I want to use my own sqlite3 database in my android project.
I created this database with command-shell line (windows) and exported it with SQLite Database Browser (sql format).
I followed this tutorial and my database can't be open :
go here to see since i can't post image
My package is org.opencv.samples and my DBName is "maif" placed in /assets directory.
So it seems that my exported database is incorrect, can someone helps me ?
I suggest to use this helper to solve your problems: https://github.com/jgilfelt/android-sqlite-asset-helper
I don't believe you can transfer an external database through the file system to Android unless you have a rooted phone. If you have to transfer data you need to use data transfer via HTTP using XML/JSON.

android \data\data folder empty

i have created a db in the phone and have inserted some values in it as well. now there is a large excel sheet which contains several more records that need to be inserted.
i am trying to find the db file in the phone so as to use sql lite db tool to upload some data in it. but the folder is empty.
can any one suggest or guide.
thanks
If you are on a real phone the /data folder will appear empty unless you have root access. An application like root explorer can allow you access to these folders (with the proper permissions). This probably isn't what you want to/should do.
If you are on an emulator you can use the file explorer in eclipse to browse your phones data/data/package folders and copy your database to and from the emulator quickly (or use adb shell commands).
Are you just doing this to test something? You should have your application insert the data you want, or create your own SQLite database and package it with your application. If you externally modify your database like this, reinstalling the application - or installing it on a different device - would result in an application still using your old/unmodified database.

How to package my android app with a database

I've already created an android application that has got an already existing sqlite 3 database within it's asset's folder. I designed the application to copy the database on to the mobile when the app is launched for the first time. My question is how can I ship the database and the app so that users can easily install the app?
thanks
The method I'm going to show you takes
your own SQLite database file from the
"assets" folder and copies into the
system database path of your
application so the SQLiteDatabase API
can open and access it normally.
Have a look here : Using your own sqlite database in your Android applications

Categories

Resources