I have one Microsoft Access .MDB file and want to use that database in an Android application.
How can I convert the .mdb database to SQLite?
You need to use some tools to convert database, refer to supported list softwares that do the job you need here: http://www.sqlite.org/cvstrac/wiki?p=ConverterTools
You can write your own - it's not very difficult
Install SQlite on your desktop - just go to sqlite.org
Get JDBC access to SQLite (there're a lot of JDBC drivers for SQLite)
Get JDBC access to your MDB (MS-Access) using JDBC (common JDBC-ODBC bridge driver is ok)
VoilĂ !
Steps to read Access files in android :
1-Creat Acces Database then,Export the access database into text files, semicolon or comma delimited.
2-Open the SQLite database browser version 1.1 ( http://sourceforge.net/projects/sqlitebrowser/files/sqlitebrowser/1.1/sqlitebrowser-1.1-win.zip/download?use_mirror=garr&download= ) and chose creat new DATABASE then enter it's name ,then file menu ->import->table from csv file. Browse for your text file and choose the proper delimiter. Click create.
3-Done.
Then you would need to make some modifications to that database and those tables to make it usable by Android to populate listviews and other widgets.
1) The database must contain a table called "android_metadata"
2) This table must have the column "locale"
3) There should be a single record in the table with a value of "en_US"
4) The primary key for every table needs to be called "_id" (this is so Android will know where to
bind the id field of your tables)
Then you put the DB in your assets folder and when your app starts copy it to your apps data directory.
Now :
Using your own SQLite database in Android applications example here:
http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/
Another excellent tool to convert the .mdb database to SQLite:
https://github.com/arturasn/mdb2sqlite
Executable direct download: https://github.com/arturasn/mdb2sqlite/blob/master/bin/mdb2sqlite.exe
Related
i`m still new to android programming, i usually code using Android Studio, here is my question about SQL lite
how do you accsess your database from your android phone?
where do you put your .db file ? some says i need to put it inside the assests folder
i often come through some tutorial where they put database name, create table, drop table query inside the sqllitehelper, why do they
put it again?
after you create the database in DB browser for sqlite software what did you do?
this is a question about android programming, i often come through some tutorial about crud or something related to database but i
dont see any INSERT INTO QUERY
do you need xampp for local server or what?
how do you accsess your database from your android phone?
If using the Android SDK, you'd typically have a Database Helper (subclass of SQLiteOpenHelper, if the database is a pre-existing database then SQLiteAssetHelper will copy the database file from the assets folder).
Note the above assumes the intended use of SQLite as an embedded database, if you want to share a database across multiple devices then SQLite would probably not be the database of choice (Firebase may be suitable).
.
where do you put your .db file ? some says i need to put it inside the
assests folder
As above, if it's a pre-existing database then the assets folder (in the case of SQLiteAssetHelper) will copy the database to the normally used /data/data//databases/ folder.
The asset file is compressed and read only so the App would copy the file to a usable folder, typically as above.
P.S. the file doesn't have to have any file extenstion or could have any valid file extenstion. Nothing that the file name MUST be the same as the database name, as that is the file that will be opened.
.
i often come through some tutorial where they put database name,
create table, drop table query inside the sqllitehelper, why do they
put it again?
This would typically be seen in the onUpgrade method.
What happens with the SQLiteOpenHelper subclass is that if the database doesn't exist, then the database is created and is from your perspective empty.
actually for android at least two system tables will exist;
1) sqlite_master which is a table of the tables and other items aka the schema, and
android_metadata which contains the locale
After the database is created the onCreate method is called and typically the tables (and possible other items, indexes, triggers, views) will be created using appropriate SQL generally invoked by using the SQLiteDatabase execSQL method.
The database is NOT created just by instantiating the helper an attempt (implied or explicit) has to be made to open the database, it is then that the database is checked for it's existence and created.
As such adding, for example, another table is NOT simply a case of adding more the onCreate method, as it will not run.
As such the SQLiteOpenHelper includes a means, by the way of the 4th parameter, the version number to facilitate upgrading the database (e.g. adding the new table).
The version number is stored in the database header and is checked by SQLiteOpenHelper against the value passed. If the value passed is greater than the stored value then onUpgrade is called.
if the value is less then onDownGrade is called and there which will result in an exception should the onDownGrade method not be coded in the sub-class of SQLiteOpenHelper.
Often, onUpgrade will DROP (delete) the tables and then call onCreate to create them and that is what you have seen (probably).
Note ANY EXISTING DATA WILL BE LOST
to not lose data you would use more complicated/in-depth code.
.
after you create the database in DB browser for sqlite software what
did you do?
Copy the file into the assets/database folder (if using SQLiteAssetHelper) or sometimes just into the assets folder.
You may have to create the assets folder and therefore also the database folder.
I would personally recommend closing DB Browser, opening it again, checking the data is as expected and then closing it again before copying the file.
this is a question about android programming, i often come through
some tutorial about crud or something related to database but i dont
see any INSERT INTO QUERY
The android SDK has many convenience methods, that build the SQL on you behalf, including (if the parameters are used accordingly) escaping arguments as required and protecting against SQL injection. Use of the convenience methods is recommended.
Here's an example of what you could instead see (to INSERT) :-
public long addUserReg(long studentId, String course) {
ContentValues cv = new ContentValues();
cv.put(COL_USERREG_STUDENT_ID,studentId);
cv.put(COL_USERREG_COURSE,course);
return mDB.insert(TBL_USERREG,null,cv);
}
The method is passed two values.
A ContentValues object is instantiated (consider this as a list of tuples with a key (name which correlates to the respective COLUMN name) and the value to be placed into that column).
A COLUMN value pair is added to the cv (an instance of a ContentValues object) COL_USERREG_STUDENT_ID holds the column name.
Another value pair is added to cv.
note you can consider cv as intelligent e.g. if you pass a byte array then the respective code for adding a BLOB is generated.
The insert convenience method is invoked, assuming COL_USERREG_STUDENT_ID resolves to studentid and COL_USERREG_COURSE resolves to course and TBL_USERREG resolves to course_table then the resultant SQL would effectively be INSERT OR IGNORE INTO course_table (studentid,course) VALUES('1','3') (assuming the studentid value passed was 1 and the course value was 3).
do you need xampp for local server or what?
No (I beleieve XAMPP is for Apache (server) MYSQL not SQLITE PHP along with PHPMYADMIN) but see above about SQLite being intended as an embedded database not a client/server type database. See Appropriate Uses For SQLite
For a schoolproject I have converted a php database from MySQL to MySQLi to use it in my android application.
I've looked into creating a android database using head's first book on android (2017) and according to that I need to manually create and insert every record in the database, but I already have all the data needed and one table even has 113 entries that need to be inserted.
Isn't there a way for me to import the existing database without completely creating it all over again?
Use SQLite browser , hope it helps .
Export SQL file from MySql and put it into assets folder. Read sql file from assets, use 'db.execSQL' method to create and insert all records of sql file. Some of the 'keywords' are working in SQLite of MySql so firstly remove these keywords from file.
I want to upload local sqlite database file at server but in sql format. Is it possible to directly save it in mysql supported format? The file is uploaded successfully on server but its just a flat file of sqlite db. When i open it in editplus or import it in phpmyadmin, it shows error. But when I manually export the database from sqlite manager in .sql extension, it successfully gets open in readable format in editplus. Please help me with this problem. Thanks in advance !
AFAIK you are talking about two completely different things.
Its like comparing a DB dump file to a properly exported file like an xml file with schema and data information from Oracle or MySql
When you export you get a file with or without .sql extension and it means a file with set of queries like DDL or DML create,insert etc. That may be sequentially run to execute all the commands in it and provide you with the right schema and data present in that file.
Whereas a DB file that is created via app is specific to the device and is an .sqlite file which is specific to sqlite browser and that may read it and not a set of queries only that you may open in edit-plus or a text editor.
Sqlite DB file that you find on your device is dynamically generated pages to maintain the integrity of the db.
For more info you must read,
Format of sqlite database
Sorry I don't have code but the idea is,
--Edit with algo--
Assuming you have the create commands for all tables and constraints with you , as they are not going to change most of the time.
You may use this function as a Utility to create and maintain the sql
command list for you parallel to the db you have.
void createExportCommands()
{
...
- Read all tables one by one using a `Cursor`
- Based on specific tables/columns create queries
i.e. String query="insert into "+your_table+" values("+cursor.getString(0),....+");";
- Write this data into a file called export_data.sql and keep updating it in background
}
Perhaps its not the best approach but it will solve your issue.
I'm new to programing for android and i'm still learning. So I have a question about the location of the SQLite database. Is it stored in the same file system as the application ?
And also i'm not sure can the database be created before the app is installed(can it come with the app) or can the database only be created from inside the app ?
And what if i wanted my app to come with a database that already has tables and records which is local and not on a server. Would that be possible ?
SQLite is available on every Android device. Using an SQLite database in Android does not require any database setup or administration.
You only have to define the SQL statements for creating and updating the database. Afterwards the database is automatically managed for you by the Android platform.
Access to an SQLite database involves accessing the filesystem. This can be slow. Therefore it is recommended to perform database operations asynchronously, for example inside the AsyncTask class.
If your application creates a database, this database is by default saved in the directory DATA/data/APP_NAME/databases/FILENAME.
The parts of the above directory are constructed based on the following rules. DATA is the path which the Environment.getDataDirectory() method returns. APP_NAME is your application name. FILENAME is the name you specify in your application code for the database.
You can also follow this tutorial for further understanding.
http://www.androidhive.info/2011/11/android-sqlite-database-tutorial/
Database is created after the app installation or after the db changes. The db is stored in /data/data/your_package/databases/
I want to only read data from the SQLite database. When I am creating database and reading it it is working but I have already a database created and I want to read data from this database.
I am pushing the database to the sdcard and trying to run the application but it is not reading form the database. I want to know that if install this .apk file in device then my database will also shift to the device or not.
Common practice is to store initial data on assets/raw folders of application resources. Then during 1st run just create DB using SQL scripts like:
create table if not exist
Fill DB with initial data - and here you're.