How to easy add data to existing database (.sql) file in Eclipse - java

I was wondering if it is possible to easily add data to existing database in Eclipse. I have a database with about 1000 records, and I don't want to put them in by hand. (In my 'update'-activity.).
I've already tried to go to DDMS - data - data - (project name) - databases, and replace the file for another file with the same name. When I do that, I get an logcat error saying:
12-15 08:47:33.495: E/SQLiteLog(4564): (26) file is encrypted or is not a database
12-15 08:47:33.495: E/DefaultDatabaseErrorHandler(4564): Corruption reported by sqlite on database: /data/data/com.jacob.eindproject/databases/Voedsel
12-15 08:47:33.495: E/DefaultDatabaseErrorHandler(4564): deleting the database file: /data/data/com.jacob.eindproject/databases/Voedsel
I can 'pull a file from the device'. Can I add data then? Somebody has an idea?
Thank you all in advance,
Jacob

Unless you will be the only user of your app, pushing data to the device or emulator manually is useless. You cannot do that for thousands of users, if for no other reason than they are unlikely to mail you their phones so you can connect the USB cable and push the file.
If your objective is to ship an app that contains starter data for the app, I recommend SQLiteAssetHelper. This is a subclass of SQLiteOpenHelper that can automatically unpack a database bundled into your app when the database is first needed.

Related

Android Room database created 3 files including -shm and -wal files

I have created a database using Room database library with name ImageDatabase, when I opened my Device File explorer in Android studio inside the database folder there were three files with names ImageDatabase, ImageDatabase-shm and ImageDatabase-wal. I wanted to know what are these files meant for? Any help would be great
Thanx All
The data in your database is contained in all three. The one with no extension is the main database. The others are the Write Ahead Log file (-wal) and the Shared Memory file (-shm). They are used by the underlying SQLite system to improve performance, and contain the latest changes to the main database until a checkpoint is done. You can find more information in the SQLite docs.
Your original database is ImageDatabase i.e name of database you give at the time of creation.
you can copy database and check the contain from here
upload your database in above link and you can verify it.

Change Database structure Sqlite

I am working on an android application on android studio, and I am using a sqlite database. The thing is, I want to change the structure of it, so do I just have to change it from DB Browser for SQLite, or I need to change it somewhere else ?
Because the code I am working on isn't mine, and I am just starting to lear android developement
An option is to change the internal structure of the database file from either DB Browser or command line on your computer and then copy it to your phone's storage when the App is running.
If you don't know the steps:
Step 1: Create a new database file from either command line or SQLite DB Browser with your required structure.
Step 2: Place the file in Assest directory in your Project folder. (Assest directory will be in the same folder as the 'res' and 'java' directories are)
Step 3: On Activity Start event, copy this empty database from Asset directory to your database directory which is generally located at /data/data/your.package/databases
Also you can query ALTER TABLE to add columns (as suggested in comments).
This explains the syntax for ALTER TABLE. It also explains other methods for implementing Schema Changes.

Simultaneous access SQLITE JAVA SERVICE / CordovaJS APP errors

Aloa
I am trying to make an app (Android to begin, and then IOS) that one side (JAVA) executes SQL statements on a database stored on the phone (imported once from the www folder and using SQLiteOpenHelper ..) in java from a background service starting at the boot. No worries on that side.
On the other hand (CordovaJS) I check / update the same database from the same application, but in the GUI (webview) via the cordova Cordova-storage-sqlite plugin. No worries either on that side ...
But when JAVA and CordovaJS try to use the database at the same time, the app crash sometimes...
How can I do to access to the base of both sides simultaneously?
Otherwise what would be the best solution:
Create two separate databases with the same information that I would need to synchronize regularly between JAVA and CordovaJS in the two ways? Synchronization can possibly lead to the same problem of dual access ...
Create two bases, and communicate via flat files containing JSON data ...
Not to use databases and move only by flat files in JSON?
Any other ideas?
I'd rather largely retain only one database ...
Thank you in advance for review
PS: Sorry for my English, I'm French :(
EDIT:
Here is one of the errors occurs: W/SQLiteConnectionPool﹕ A SQLiteConnection object for database '+data+data+com_app+databases+db.db' was leaked! Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
An other error seems like android.database.sqlite.SQLiteException: error code 5: database is locked

Android: Adding database to apk

OK so here's the deal. I'm developing apk and I'd like to add database (atm at .txt) so my question is:
How should I add it to my apk, just load it all to table or there is any better way to do it?
And after that I'd like to click on button and be able to start writing item from base and phone would help out. For example I've got in database chicken breast, chicken leggs, eggs
and when I write "br" my apk shows most accurate position.
ps. my database got about 3k positions.
If you want to access a file when creating an app you can place it in the assets folder inside of your project. You could then call Context.getAssets().open("FILENAME") to access it as an input stream.
You might want to consider a sqlitedb instead of a text file,The following tutorial can assist you in setting up an android project using a sqlite db.
http://www.vogella.com/tutorials/AndroidSQLite/article.html

Exception while trying to open sqlite DB with having pagesize as 64KB

I have a java program which interacts with SQLite DB having journal_mode as delete.
This program works fine for all DB and I am able to do transactions as far as DB has pagesize of 32 KB.
But there is one sqlite DB which is having pagesize as 64 KB. And when I try to execute
stmt.executeQuery();
on that DB, it gives me exception
java.sql.SQLException: [SQLITE_NOTADB] File opened that is not a database file (file is encrypted or is not a database)
Can anybody please let me know what could be the solution for this? This DB is not encrypted and having journal_mode as delete only.
I am able to open this DB with SQLITESpy tool though.
Thanks
If the database is open by another application and has wal and shm files open I get the same strange error. Since i do not want to bother with such strange design internall details I am using the following workaround:
echo ".dump" | sqlite3 database.db | sqlite3 dbcopy.db
and work on the copy for queries. I even get protected from database corruption problems this way that seem to plague the "new" sqlite design as well. I wish the sqlite designers would make sure that there external interface is much more stable and clean and does not show such internal design problems as failures and corruptions.
Using 64 KB pages requires SQLite 3.7.1 or later.

Categories

Resources