Click here to Skip to main content
15,907,497 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
First off all i am the beginner to android.If i make some mistake so sorry for that. so now i want to store the image in android database which take this image from the image view.the image will hold by the imageview which is taken by camera. the database class is:

Java
  public class DatabaseOperation extends SQLiteOpenHelper {
SQLiteDatabase db;

public static final String DATABASE_NAME = "Student.db";
public static final String TABLE_NAME = "student_table";
public static final String COL_1 = "ID";
public static final String COL_2 = "NAME";
public static final String COL_3 = "PASS";
public static final String COL_4 = "CONTACT";
public static final String COL_5 = "NIC";
public static final String COL_6= "CONFIRM";
  public static final String IMAGE_KEY="IMAGE";

public DatabaseOperation (Context context) {

    super(context, DATABASE_NAME, null, 1);

}

@Override
public void onCreate(SQLiteDatabase db) {
    db.execSQL("create table " + TABLE_NAME +" (ID INTEGER PRIMARY KEY AUTOINCREMENT,NAME TEXT,PASS TEXT,CONFIRM TEXT,NIC INTEGER,CONTACT INTEGER,IMAGE_KEY BLOB)");
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    db.execSQL("DROP TABLE IF EXISTS "+TABLE_NAME);
    onCreate(db);
}
public  boolean insertData(String name,String pass,String confrim,String contact,String nic,byte[]image)
{
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues cv=new ContentValues();
    cv.put(COL_2,name);
    cv.put(COL_3,pass);
    cv.put(COL_6,confrim);
    cv.put(COL_4,contact);
    cv.put(COL_5,nic);
    cv.put(IMAGE_KEY,image);
   long result= db.insert(TABLE_NAME,null,cv);
    if(result==-1)
        return false;
    else
        return true;

    }<a href="file:///C:/Users/prince/Pictures/Camera%20Roll/WIN_20160723_15_31_31_Pro%20(2).jpg"></a>


and this is the activity class

C#
public void reg(View v)
     {

   if(!(pass.getText().toString().equals(confirm.getText().toString())))
               {
                   showMessage("Error!","Password not matched");
                   pass.setText("");
                   confirm.setText("");
               }
               else {

                   boolean isInserted = myDb.insertData(name.getText().toString(), pass.getText().toString(),
                           confirm.getText().toString(), cont.getText().toString(), nic.getText().toString());


                   if (isInserted == true)
                       Toast.makeText(getBaseContext(), "Registration Succes!", Toast.LENGTH_SHORT).show();
                   else

                   Toast.makeText(getBaseContext(), "No Record     Registered!", Toast.LENGTH_SHORT).show();


               }


What I have tried:

Now i want to store the image in the android database from the imageview by clicking the register button.
Posted
Updated 26-Jul-16 1:42am
v2
Comments
Vincent Maverick Durano 26-Jul-16 7:44am    
Have you tried search for it at google? I tried this search key "store image in android", and it gives back tons of results. This is one of them:

http://sunil-android.blogspot.com/2013/10/insert-and-retrieve-image-into-db.html

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900