I am new to android so have very less idea about working of images in sqlite db. I am creating an app in which i will be creating a db with pre-filled data that means i would be putting that data-filled db in assets folder and user will start using it directly once the app is installed.
So i have around 186 images of flags from different countries, which i need to show in a custom listview. Can you tell me how to store all images in sqlite db and get it back to show on listview?
I tried using some IDE for inserting images in db but their decoding doesn't work.
Please help!!!
try this First of all you have to store all images in blob datatype into sqlite database then for retrieving from database user following code
query_compnay_id="Select * From "+mStaticValues.company_master;
mCursor_company_detail=mDatabaseConnectionAPI.ExecuteQueryGetCursor((query_compnay_id));
mCursor_company_detail.moveToFirst();
byte[] by =mCursor_company_detail.getBlob(mCursor_company_detail.getColumnIndex(mStaticValues.image_data));
mBitmap=BitmapFactory.decodeByteArray(by, 0, by.length, null);
Related
Can I add books to my SQLite database in android??
If yes, how?
I want to put the books on database because I've too many books to add to the android app and I don't want to make the size of the Application too much.
There's a limit of 1MB on internal assets due to dynamic decompression; the 1MB >limit also seems to apply to Cursor blobs but this doesn't seem to be >documented anywhere.
Generally you should avoid blobs in SQLite as they perform poorly; instead, >save the blob data as a file and store the location of the file in your DB
I won't recommend storing pdf flies in SQLite, you can just provide a simple link to download it to the user. but if you want to store it here you can do something like this.
First, you need to convert the pdf file into a byte array
import java.nio.file.*;
Path pdfFilePath = Paths.get("/file/path/your_file.pdf");
// Read file to byte array
byte[] pdfByteArray = Files.readAllBytes(pdfFilePath );
// Write byte array to file
Files.write(pdfFilePath , pdfByteArray);
You're looking for BLOB to store the data in android SQLite.
BLOB - The value is a blob of data, stored exactly as it was input.
Here's an example of making a table with two columns - an id and some data, which is a BLOB:
just for an example, you can create a table like this
CREATE TABLE t1 (id INTEGER PRIMARY KEY, data BLOB);
You can't do it. you cant store files in SQLite database. You will store your files in asserts folder.
I have 600+ text files. How do I put them in a database, with mySQL lite.
I want to have 3 columns: index(1 to 600), title and content.
How do I do that? Thanks.
http://www.sqlite.org/datatype3.html
When you create the database (the single table in it), the index should be auto-generated when the entry is created in the table (if you properly created the table with auto indexing)
I would use TEXT (varchar) for the title & blob for the actual text file (the data in it).
The previous answer seems to put you on the right track, though I'm not sure I quite understand how you intend to actually populate the table with the data.
Use content provider for android below is nice link.
http://www.vogella.com/tutorials/AndroidSQLite/article.html.
For datatype to use integer,text,text as columns, below is
datatype link of sqlite.
http://www.sqlite.org/datatype3.html
But Instead of storing the file data in sqlite, I would suggest you to store sdcard path of files in sqlite table and retreive from sdcard when required.
In above case columns will be index,title,filepath.
I have a question about SQLite. I'm trying to save a custum objects (let's say ObjectA) on my phone's db. ObjectA contains an ArrayList.
I'll probably have to save the images as BLOBs but how should I design my database. Should I create a new table with all my pictures (BLOB byte[], INTEGER objectA_row_id) ? or is there another way to make this association?
May be create table with path to the pictures.
You shouldn't store file path directly in database, because if you delete the file then you will not get image, so you have 2 options:
1) Store image to your cache/internal and then save its file path.
2) Use database table containing BLOB type.
I want to insert values from edittext and select image and then store it into the database and retrieve in listview. I successfully inserted the edittext values like name and password in listview bt dont know how to insert images and retrieve it with name and all stuff. plz give some sample code.
thanks in advance!
hi the below link shows how to upload image to the locally server link and save the url,name,password in database table
load all images form the URL and data & display it efficiently using lazy list view refer this lazylist link
First create a custom list view follow the link given below
http://www.androidhive.info/2012/02/android-custom-listview-with-image-and-text/
and store data into DataBase use
http://www.androidhive.info/2012/02/android-custom-listview-with-image-and-text/
Storing image in Sq lite using Blob is not an efficient way.
store the captured image in sdcard. and store the image uri to sqlite table.And retrieve from path. you can use timestamps for retrieving..
I am dealing with ECG signal processing using Android phone. I am getting the filtered ECG signal after the series of operations as my final output, and it is saved in text file in particular location. The text file contains the values of voltages in a single column, containing 30000 samples. This is done for number of patients.
Now I have to use these text files in my database with particular patients, as a entry in their row.
I am using SQLite database.
How can it be done?
please help me with this.
Read the file and save it as blob in sqlite, but if data is too large, you will have problems with size. Another way would b to keep the files in sdcard with some id as filename, you could save these ids in db which you can refer.
OK basically what you need to do is:
bulkinsert your data.
here is the link on how to do it:
http://notes.theorbis.net/2010/02/batch-insert-to-sqlite-on-android.html
if you need to populate your second table with this data then
update yourtable set blah=(select field from yourfreshlypopulatedtable)