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:
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
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.