Tuesday, 2 October 2012

Sax Parser Data Handler


public class DataHandler 
{
 private SQLiteDatabase sqLiteDatabase;
 MyHelper myHelper;
 Context context;
 public DataHandler(Context context) {
 myHelper = new MyHelper(context, "College.sqlite", null,1);
 }
 
 public class MyHelper extends SQLiteOpenHelper
 {

  public MyHelper(Context context, String name, CursorFactory factory,
    int version) {
   super(context, name, factory, version);
   // TODO Auto-generated constructor stub
  }

  @Override
  public void onCreate(SQLiteDatabase db) {
   // TODO Auto-generated method stub
   
   db.execSQL("create table Student(sno text,sname text ,city text)");
   
  }

  @Override
  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
   // TODO Auto-generated method stub
   
  }
  
 }
 
 public void openDataBase()
 {
  
  sqLiteDatabase = myHelper.getWritableDatabase();
 }
 public void insertStudent(Vector<Student> vecStudent)
 {
  openDataBase();
  Student student;
  ContentValues contentValues = null;
  for(int i = 0;vecStudent.size()>0;i++)
  {
  student = vecStudent.get(0);
   contentValues = new ContentValues();
  contentValues.put("sno", student.sno);
  contentValues.put("name", student.name);
  contentValues.put("city", student.city);
  sqLiteDatabase.insert("Student", "", contentValues);
  }
  
  
 }
 public void closeDataBase()
 {
  sqLiteDatabase.close();
 }
}

No comments:

Post a Comment