User talk:Key24

package com.testapp.modelpaper;

import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper;

public class DBHelper extends SQLiteOpenHelper{

public static final String DatabaseName = "databse.db";

public static final String TableName = "UserInfo"; public static final String col1 = "_ID"; public static final String col2 = "userName"; public static final String col3 = "dateOfBirth"; public static final String col4 = "Gender"; public static final String col5 = "Password";

public DBHelper(Context context) { super(context, DatabaseName, null, 1); }

@Override public void onCreate(SQLiteDatabase db) { db.execSQL("create table "+ TableName + " (" + col1+" integer primary key AutoIncrement," + col2 +" text ,"+col3+" text,"+col4+" text,"+col5+" text)"); }

@Override public void onUpgrade(SQLiteDatabase db, int i, int i1) { db.execSQL("drop table if exists "+TableName); }

public boolean addInfo(String name,String dob,String gender, String password){ SQLiteDatabase db = getWritableDatabase; ContentValues cval = new ContentValues; cval.put(col2,name); cval.put(col3,dob); cval.put(col4,gender); cval.put(col5,password); int i= (int) db.insert(TableName,null,cval); if(i > 0){ return true; }else { return false; }   }

public boolean updateInfo(String name,String dob,String gender, String password){ SQLiteDatabase db = getWritableDatabase; ContentValues cval = new ContentValues; cval.put(col2,name); cval.put(col3,dob); cval.put(col4,gender); cval.put(col5,password); int i= db.update(TableName,cval, col2+"=\""+ name + "\"",null); if(i > 0){ return true; }else { return false; }   }

public Cursor readAllInfo{ SQLiteDatabase db = getWritableDatabase; Cursor cursor= db.rawQuery("select * from "+TableName+"",null); return cursor;

}

public Cursor readAllInfo(String name){ SQLiteDatabase db = getWritableDatabase; Cursor cursor= db.rawQuery("select * from "+TableName+" where "+col2 +"=\""+name+"\"",null); return cursor;

}

public boolean deleteInfo(String name){ SQLiteDatabase db = getWritableDatabase; int i= db.delete(TableName,col2+"=\""+name+"\"",null); if(i > 0){ return true; }else { return false; }   }

}