public class DatabaseHelper extends SQLiteOpenHelper {
public static String DBname = "Details";
public static String TblName = "UsrRegtr";
public static String Colid = "usrid";
public static String ColUser = "UsrName";
public static String ColPass = "Password";
public static String ColPhNo = "PhoneNo";
public DatabaseHelper(Context context) {
super(context, DBname, null, 2);
// TODO Auto-generated constructor stub
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE UsrRegtr(usrid INTEGER AUTO INCREMENT PRIMARY KEY ,UsrName TEXT,Password TEXT,PhoneNo NUMERIC)");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
}
public void AddUsr(user usr) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put(ColUser, usr.getNAME());
cv.put(ColPass, usr.getPASS());
cv.put(ColPhNo, usr.getPHNO());
db.insert(TblName, Colid, cv);
db.close();
}
public int getusrCount() {
SQLiteDatabase db = this.getWritableDatabase();
Cursor cur = db.rawQuery("Select * from " + TblName, null);
int x = cur.getCount();
cur.close();
return x;
}
public Cursor getalldata(){
return(getReadableDatabase().rawQuery("SELECT UsrName,PhoneNo FROM UsrRegtr", null));
}
public String getUsername(Cursor c){
return c.getString(2);
}
}
0 comments: