when i use this code to store image in sqlite , I get only the first image , the application not restore to me the other images By the id : when i use this code to store image and restore it from SQLite . it insert only one image (the first one ) and when i restore the image by id it also restore the first image only .  

activity_main.xml 

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
        android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
    
        <EditText
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:textSize="24dp"
        android:hint="enter name"
        android:id="@+id/nametxt"
        android:layout_marginTop="350dp"
        />
        <EditText
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:textSize="24dp"
            android:hint="enter id"
            android:id="@+id/idtxt"
            android:layout_marginTop="420dp"
            />
        <Button
            android:textSize="20dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Save Image Sqlite"
            android:id="@+id/button"
            android:layout_below="@+id/imageView"
            android:layout_marginTop="75dp"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true" />
    
        <Button
            android:textSize="20dp"
    
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Get Image From Sqlite"
            android:id="@+id/button2"
            android:layout_below="@+id/button"
            android:layout_marginTop="42dp"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true" />
    
        <ImageView
            android:background="@color/colorPrimaryDark"
            android:layout_width="120dp"
            android:layout_height="120dp"
            android:id="@+id/imageView2"
            android:layout_alignParentTop="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true" />
    
        <ImageView
            android:background="@color/colorAccent"
            android:layout_width="120dp"
            android:layout_height="120dp"
            android:id="@+id/imageView"
            android:scaleType="fitCenter"
            android:maxHeight="120dp"
            android:maxWidth="120dp"
            android:layout_alignParentTop="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true" />
    </RelativeLayout>

MainActivity.java

    package com.example.mahmoudbelal.navigator;
    
    import android.content.Intent;
    import android.database.Cursor;
    import android.database.sqlite.SQLiteDatabase;
    import android.graphics.Bitmap;
    import android.graphics.BitmapFactory;
    import android.net.Uri;
    import android.os.Bundle;
    import android.provider.MediaStore;
    import android.support.v7.app.AppCompatActivity;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.ImageView;
    import android.widget.Toast;
    
    import java.io.ByteArrayOutputStream;
    
    public class MainActivity extends AppCompatActivity {
        private static int RESULT_LOAD_IMG = 1;
        String imgDecodableString;
    static  EditText name,id;
    
    
    
      static   ImageView Img,Img2;
        Button Save,Get;
        SQLiteDatabase db;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    id= (EditText) findViewById(R.id.idtxt);
            Img = (ImageView) findViewById(R.id.imageView);
            Img2 = (ImageView) findViewById(R.id.imageView2);
            Save = (Button) findViewById(R.id.button);
            Get = (Button) findViewById(R.id.button2);
            name= (EditText) findViewById(R.id.nametxt);
    
    
    
            Img.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Intent galleryIntent = new Intent(Intent.ACTION_PICK,
                            android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                    // Start the Intent
                    startActivityForResult(galleryIntent, RESULT_LOAD_IMG);
                }
            });
    
            Save.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
    
                   try {
    
    
                       Img.buildDrawingCache();
                       Bitmap bitmap=Img.getDrawingCache();
    
                       ByteArrayOutputStream bos = new ByteArrayOutputStream();
                       bitmap.compress(Bitmap.CompressFormat.PNG, 100, bos);
                       byte[] img = bos.toByteArray();
    
                      DBAdapter D=new DBAdapter();
                       D.open(MainActivity.this);
                       String myname=name.getText().toString();
                       String myid=id.getText().toString();
    
                       D.insert_user_data(myid,myname,img);
    
                       Toast.makeText(MainActivity.this, "Inserted Data well !", Toast.LENGTH_SHORT).show();
    
                       name.setText(" ");
                       id.setText(" ");
    
                   }catch (Exception e){
                       Toast.makeText(MainActivity.this, ""+e.getMessage(), Toast.LENGTH_SHORT).show();
    
                   }
                }
            });
    
    //------------------------------------------------------------------------------------//\
    
    
            Get.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                  
                    DBAdapter D=new DBAdapter();
                    D.open(MainActivity.this);
                   String use_id=id.getText().toString();
                    D.Get_user_data(use_id);
                    if (DBAdapter.ok.equals("1")){
                      //  Img2.setImageBitmap(DBAdapter.bmp);
                       // Toast.makeText(MainActivity.this, "name is  =  "+DBAdapter.s, Toast.LENGTH_SHORT).show();
                        name.setText(""+DBAdapter.s);
    
                    }else
                    {
    
                        Toast.makeText(MainActivity.this, "Error y m3lm ", Toast.LENGTH_SHORT).show();
                    }            }
            });
        }
    
    
        @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            super.onActivityResult(requestCode, resultCode, data);
    
    
    
            // When an Image is picked
            if (requestCode == RESULT_LOAD_IMG && resultCode == this.RESULT_OK
                    && null != data) {
                // Get the Image from data
    
                Uri selectedImage = data.getData();
                String[] filePathColumn = {MediaStore.Images.Media.DATA};
    
                // Get the cursor
                Cursor cursor = getContentResolver().query(selectedImage,
                        filePathColumn, null, null, null);
    
                cursor.moveToFirst();
    
                int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
                imgDecodableString = cursor.getString(columnIndex);
    
    //-0-------------------------------------------------------------------------------------------------------------
                Uri photoUri = data.getData();
                String[] proj = {MediaStore.Images.Media.DATA};
    
                Cursor actualimagecursor = managedQuery(photoUri, proj, null, null, null);
                int actual_image_column_index = actualimagecursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
                actualimagecursor.moveToFirst();
    
                //--------------------------------------------------------------------------------------------
                cursor.close();
    
                Img.setImageBitmap(BitmapFactory.decodeFile(imgDecodableString));
    
                Toast.makeText(MainActivity.this, "Image Uploaded", Toast.LENGTH_LONG).show();
    
    
            } else {
                Toast.makeText(MainActivity.this, "You haven't picked Image", Toast.LENGTH_LONG).show();
            }}
    
    
    
    
    
        }

DBAdapter.java

    package com.example.mahmoudbelal.navigator;
    
    import android.content.ContentValues;
    import android.content.Context;
    import android.database.Cursor;
    import android.database.sqlite.SQLiteDatabase;
    import android.database.sqlite.SQLiteOpenHelper;
    import android.graphics.Bitmap;
    import android.graphics.BitmapFactory;
    
    public class DBAdapter {
        // first step:create table
      static   Bitmap bmp;
       static String s="";
        private int version=1;
        private String DatabaseName="DNAA";
        private String TableName="user";
        static  String ok;
    //                             --------------------------------------------------                             //
    
    
        private String create_table = "CREATE TABLE IF NOT EXISTS user(id varchar,name varchar,img blob);";
    
    
    
        // second step:helper class
        class DbHellper extends SQLiteOpenHelper{
    
    
            public DbHellper(Context context){
                super(context , DatabaseName , null , version);
            }
    
            @Override
            public void onCreate(SQLiteDatabase db) {
                db.execSQL(create_table);
            }
    
            @Override
            public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    
                db.execSQL("Drop table If Exists "+TableName);
                onCreate(db);
    
            }
        }
    
    
        private DbHellper DB_helper;
        private SQLiteDatabase db;
    
        public DBAdapter open(Context conn){
            DB_helper = new DbHellper(conn);
            db = DB_helper.getWritableDatabase();
            return this;
    
            // activity
        }
    
        private void close (){
            db.close();
        }
        int i = 0;
    
        public void insert_user_data (String id, String name, byte[] ii){
            ContentValues cv = new ContentValues();
    
    
            cv.put("id" , id);
            cv.put("name" , name);
            cv.put("img" , ii);
    
            db.insert(TableName, null, cv);
    
        }
    
        public void updateSection(String username , String password , int rowId){
            ContentValues cv = new ContentValues();
            cv.put("username" , username);
            cv.put("password" , password);
            db.update(TableName, cv, "_id =" + rowId, null);
        }
    
        // Login method
        public  void  Get_user_data (String id){
    
        Cursor c = db.rawQuery("SELECT name,img FROM user where id='"+id+"'", null);
            if (c.moveToFirst()) {
                 s= c.getString(0);
                byte[] i=c.getBlob(1);
    
                 bmp= BitmapFactory.decodeByteArray(i,0,i.length);
                MainActivity.Img2.setImageBitmap(bmp);
    
              ok="1";
            } else {
                ok="0";
            }
        }
        // delete data
        public void deleteSection(int rowId){
            db.delete(TableName, "_id =" + rowId, null);
        }
    
        public Cursor getAllSections (){
            return db.query(TableName,new String []{"username","password"},null,null,null,null,null);
        }
    
        public Cursor getSection (String whereClause){
            return db.query(TableName,new String []{"_id","name","devices"},whereClause,null,null,null,null);
        }
    }

