what i wrong in the following code
Database code:
public class DatabaseOperation extends SQLiteOpenHelper {
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 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)");
}
@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)
{
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);
long result= db.insert(TABLE_NAME,null,cv);
if(result==-1)
return false;
else
return true;
}
public Cursor getAllData()
{
SQLiteDatabase db=this.getWritableDatabase();
Cursor res=db.rawQuery("select * from "+TABLE_NAME,null);
return res;
}
public boolean updateData(String id,String name,String pass,String confrim,String contact,String nic)
{
SQLiteDatabase db=this.getWritableDatabase();
ContentValues cv=new ContentValues();
cv.put(COL_1,id);
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);
db.update(TABLE_NAME,cv, "ID= ?",new String[]{id});
return true;
}
public Integer deletData(String id)
{
SQLiteDatabase db=this.getWritableDatabase();
return db.delete(TABLE_NAME, "ID = ?",new String[] {id});
}
public boolean checkIfRecordExist(String TABLE_NAME,String COL_2,String chek)
{
try
{
SQLiteDatabase db=this.getReadableDatabase();
Cursor cursor=db.rawQuery("SELECT "+COL_2+" FROM "+TABLE_NAME+" WHERE "+COL_2+"='"+COL_2+"'",null);
if (cursor.moveToFirst())
{
db.close();
Log.d("Record Already Exists", "Table is:"+TABLE_NAME+" ColumnName:"+COL_2);
return true;
}
Log.d("New Record ", "Table is:"+TABLE_NAME+" ColumnName:"+COL_2+" Column Value:"+COL_2);
db.close();
}
catch(Exception errorException)
{
Log.d("Exception occured", "Exception occured "+errorException);
}
return false;
}
}
and this is the activity class;
registr.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
boolean recordExists= myDb.checkIfRecordExist(DatabaseOperation.TABLE_NAME ,DatabaseOperation.COL_2 ,name.getText().toString());
if(recordExists)
{
Toast.makeText(getBaseContext(), "exist", Toast.LENGTH_SHORT).show();
}
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(), "INSERTED", Toast.LENGTH_SHORT).show();
else
Toast.makeText(getBaseContext(), "not inserted", Toast.LENGTH_SHORT).show();
}
});
What I have tried:
I tried more but did'nt get.I added this class but did'nt show any thing althoug it did'nt show me any error but could'nt show the result