public class DBHelper extends SQLiteOpenHelper
{
private static final String DATABASE_NAME = "Student";
private static final int DATABASE_VERSION = 1;
private static final String TABLE_USER = "Marks";
private SQLiteDatabase db;
private static String DB_PATH = "";
private Context mycontext;
private String today;
private static String CREATE_TABLE_USER = "create table Marks
(ASid integer primary key autoincrement, Name text, Marks integer);";
public DBHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
DB_PATH = "/data/data/" +
context.getPackageName() + "/databases/";
}
@Override
public void onCreate(SQLiteDatabase db) {
//db.execSQL(CREATE_TABLE_USER);
}
public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {}
public static boolean
isTableExist(SQLiteDatabase db)
{
Cursor cursor = db.rawQuery("select DISTINCT
tbl_name from sqlite_master where tbl_name = '"+TABLE_USER+"'", null);
if(cursor!=null)
{
if(cursor.getCount()>0)
{
cursor.close();
return true;
}
cursor.close();
}
return false;
}
private static boolean isDataBaseExist()
{
File file =new File(DB_PATH + DATABASE_NAME);
return file.exists();
}
public DBHelper opendb() throws SQLException
{
isDataBaseExist();
if (isDataBaseExist() == false)
{
db=getWritableDatabase();
if (db.isOpen())
db.close();
}
db = getWritableDatabase();
boolean tableExsist = isTableExist(db);
if(! tableExsist)
{
db.execSQL(CREATE_TABLE_USER);
}
return this;
}
public void closedb() {
db.close();
}
public void AddRecords(String Name, Integer Marks)
{
Date
d = new Date();
SimpleDateFormat
curFormater = new SimpleDateFormat("dd/MM/yyyy");
String
today = curFormater.format(d);
try
{
ContentValues
initialValues = new ContentValues();
db =
getWritableDatabase();
initialValues.put("Name", Name);
initialValues.put("Marks", Marks);
db.insert(TABLE_USER, null, initialValues);
}
catch(Exception e)
{
e.printStackTrace();
}
}
public boolean CheckASList(String
Name, Integer Marks)
{
db = getReadableDatabase();
boolean flg = false;
try
{
Cursor cursor = db.query(TABLE_USER,
null, "Name" + " = '" + Name +"'" +" AND
" + "Marks" + " = '" + Marks+"'", null,null, null, null);
int size = cursor.getCount();
if(size > 0)
{
flg = true;
}
}
catch(Exception e)
{
e.printStackTrace();
}
return flg;
}
public ArrayList<ListBean> SelectStudentList(Integer Marks)
{
db = getReadableDatabase();
ArrayList<ListBean> Beans= new ArrayList<ListBean>() ;
boolean flg = false;
try
{
Cursor cursor = db.query(TABLE_USER,
null, "Narks" + " > '" + Marks +"'" , null,
null, null, null);
int size = cursor.getCount();
if(size > 0)
{
cursor.moveToFirst();
for(int i=0; i<size; i++)
{
flg = true;
String
Name = cursor.getString(0);
String Marks=
cursor.getString(1);
ListBean
ASbean = new ListBean() ;
ASbean.setName(Name);
ASbean.Marks(Marks);
Beans.add(i, ASbean);
cursor.moveToNext();
}
cursor.close();
}
}
catch(Exception e)
{
e.printStackTrace();
}
return Beans;
}
public int getCount()
{
db = getReadableDatabase();
Cursor cursor = db.query(TABLE_USER,
null, null, null,
null, null, null);
int size = cursor.getCount();
return size;
}
}