mercredi 13 janvier 2016

upload an image to my sqlite database andorid

Hello i'm builnding an app that contains a navigation drawer with a circle profile image , i want to upload an image to my sqlite database any help please and thats my dbAdapter code (Note i'm using fragments in the navigation drawer) :

public class LoginDataBaseAdapter

    static final String DATABASE_NAME = "database.db";
    static final int DATABASE_VERSION = 1;
    public static final int NAME_COLUMN = 1;
    // TODO: Create public field for each column in your table.
    // SQL Statement to create a new database.
    static final String DATABASE_CREATE = "create table "+"LOGIN"+
                                 "( " +"ID"+" integer primary key autoincrement,"+"NAME text, "+ "image blob, "+ "USERNAME  text,PASSWORD text); ";
    // Variable to hold the database instance
    public SQLiteDatabase db;
    // Context of the application using the database.
    private final Context context;
    // Database open/upgrade helper
    private DataBaseHelper dbHelper;
    public  LoginDataBaseAdapter(Context _context)
    {
        context = _context;
        dbHelper = new DataBaseHelper(context, DATABASE_NAME, null, DATABASE_VERSION);
    }
    public  LoginDataBaseAdapter open() throws SQLException
    {
        db = dbHelper.getWritableDatabase();

        return this;
    }
    public void close() 
    {
        db.close();
    }

    public SQLiteDatabase getDatabaseInstance()
    {
        return db;
    }

    public void insertEntry(String name ,String userName,String password)
    {
       ContentValues newValues = new ContentValues();
        // Assign values for each row.
        newValues.put("NAME",name);
        newValues.put("USERNAME", userName);
        newValues.put("PASSWORD",password);



        // Insert the row into your table
        db.insert("LOGIN", null, newValues);
        ///Toast.makeText(context, "Reminder Is Successfully Saved", Toast.LENGTH_LONG).show();
    }
    public int deleteEntry(String UserName)
    {
        //String id=String.valueOf(ID);
        String where="USERNAME=?";
        int numberOFEntriesDeleted = db.delete("LOGIN", where, new String[]{UserName}) ;
       // Toast.makeText(context, "Number fo Entry Deleted Successfully : "+numberOFEntriesDeleted, Toast.LENGTH_LONG).show();
        return numberOFEntriesDeleted;
    }   
    public String getSinlgeEntry(String userName)
    {
        Cursor cursor=db.query("LOGIN", null, " USERNAME=?", new String[]{userName}, null, null, null);
        if(cursor.getCount()<1) // UserName Not Exist
        {
            cursor.close();
            return "NOT EXIST";
        }
        cursor.moveToFirst();
        String password= cursor.getString(cursor.getColumnIndex("PASSWORD"));
        cursor.close();
        return password;                
    }
    public String getName (String userName){
        Cursor cursor=db.query("LOGIN", null, " USERNAME=?", new String[]{userName}, null, null, null);
        if(cursor.getCount()<1)
        {
            cursor.close();
            return "NOT EXIST";
        }
        cursor.moveToFirst();
        String name = cursor.getString(cursor.getColumnIndex("NAME"));
        cursor.close();
        return  name;
    }

    public  boolean Exist(String userName) {
        Cursor cursor = db.query("LOGIN", null, " USERNAME=?", new String[]{userName}, null, null, null);
        if(cursor.getCount()>0) {
            cursor.close();
            return true;
        }
        return  false;
    }

    public void  updateEntry(String name,String userName, String password)
    {
        // Define the updated row content.
        ContentValues updatedValues = new ContentValues();
        // Assign values for each row.
        updatedValues.put("NAME",name);
        updatedValues.put("USERNAME", userName);
        updatedValues.put("PASSWORD",password);


        String where= "USERNAME = ?";
        db.update("LOGIN", updatedValues, where, new String[]{userName});
    }

}

Aucun commentaire:

Enregistrer un commentaire