Hey Folks am making a simple application in which ill insert two accounts manually into a table for the login authentication and then after that ill do some working based on the accounts type. Am having issues in setting up Sqlite functions. I have one package com.example.emp_management and in it i have 2 classes MainActivity.java and Database_Wrap.java. Code for the Database_Wrap.java is given below:
package com.example.emp_management;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class Database_Wrap //hotornot
{
public static final String Database_name = "Employee_Managament_System";
public Sql_Lite_Work OurHelper;
public final Context OurContext;
public SQLiteDatabase ourDatabase;
public static class Sql_Lite_Work extends SQLiteOpenHelper
{ //dbhelper = sql_lite_work
public Sql_Lite_Work(Context context)
{
super(context,Database_name , null, 1);
// TODO Auto-generated constructor stub
}
@Override
public void onCreate(SQLiteDatabase db)
{
// TODO Auto-generated method stub
db.execSQL("CREATE TABLE" + "Login_Authentication"+ "(" +
"ID" + "INTEGER PRIMARY KEY AUTOINCREMENT, " +
"UserName" + "TEXT NOT NULL," +
"Password" + "TEXT NOT NULL);"
);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
{
// TODO Auto-generated method stub
db.execSQL("DROP TABLE IF EXISTS " + "Login_Authentication");
onCreate(db);
}
}
public Database_Wrap(Context c)
{
OurContext = c;
}
public Database_Wrap Open()
{
OurHelper = new Sql_Lite_Work(OurContext);
ourDatabase = OurHelper.getWritableDatabase();
return this;
}
public void close()
{
OurHelper.close();
}
}
Now next thing i want to do is in my mainactivity i want to do something like:
Database_Wrap entry= new Database_Wrap(MainActivity.this);
and then acces the function written in Database_Wrap to open the database and write the values into table for admin and other users:
entry.Open();
but in eclipse am not able to access open function on entry. I dnt know what is wrong here. Am a beginer. May be am forgetting something. Kindly have a look thankyou!