Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8946991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:38:08+00:00 2026-06-15T12:38:08+00:00

I am trying to insert data in sqllite database in android. my Adapterclass public

  • 0

I am trying to insert data in sqllite database in android.

my Adapterclass

public class dbAdapter {
    // Database fields
    public static final String ID = "id";
    public static final String FULLNAME = "fullname";
    public static final String ADDRESS = "address";
    public static final String EMAIL = "email";
    public static final String MOBILE = "mobile";
    public static final String GENDER = "gender";
    public static final String DOB = "dob";
    public static final String CITY = "city";
    public static final String USERNAME = "username";
    public static final String PASSWORD = "password";

    private static final String DATABASE_TABLE = "myfirstanroidapp";

    private Context context;
    private SQLiteDatabase database;
    private databaseHelper dbHelper;

    public dbAdapter(OnClickListener onClickListener) {
        this.context = (Context) onClickListener;
        open();
    }

    public dbAdapter(Context context) {
        Log.e("Adapter","dbAdapter context");
        this.context = context;
    }

    public dbAdapter open() throws SQLException {

        dbHelper = new databaseHelper(context);
        Log.e("Adapter","getWritableDatabase");
        database = dbHelper.getWritableDatabase();
        return this;
    }

    public void close() {
        dbHelper.close();
    }

    // Put String values into a Content object(like AssignData to database field)
    private ContentValues createContentValues(String fullname, String address, String email,String mobile, String gender, String dob,String city, String username, String password) {
        ContentValues values = new ContentValues();
        values.put(FULLNAME, fullname);
        values.put(ADDRESS, address);
        values.put(EMAIL, email);
        values.put(MOBILE, mobile);
        values.put(GENDER, gender);
        values.put(DOB, dob);
        values.put(CITY, city);
        values.put(USERNAME, username);
        values.put(PASSWORD, password);
        return values;
    }

    // Create a new myfirstanroidapp. If the myfirstanroidapp is successfully created return the new
    // rowId for that note, otherwise return a -1 to indicate failure.
    public long insert(String fullname, String address, String email,String mobile, String gender, String dob,String city, String username, String password) {  
        ContentValues assigndata = createContentValues(fullname,address,email,mobile,gender,dob,city,username, password) ;  
        return database.insert(DATABASE_TABLE, null, assigndata);
    }
}

my Helperclass

public class databaseHelper extends SQLiteOpenHelper 
{
    private static final String DATABASE_NAME = "myfirstanroidapp";
    private static final int DATABASE_VERSION = 1;
    // Database creation SQL statement
    private static final String DATABASE_CREATE = 
            "create table myfirstanroidapp (id integer primary key autoincrement, " +
            "fullname text not null, address text, " +
            "mobile text not null, email text not null," +
            "city text not null, username text not null, " +
            "password text not null, dob text not null," +
            "gender text not null);";


    public databaseHelper(Context context){     
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
        Log.e("Database",DATABASE_NAME);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        //Create Database
        db.execSQL(DATABASE_CREATE);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        //Drop Database and ReCreate Database
        db.execSQL("DROP TABLE IF EXISTS myfirstanroidapp");
        onCreate(db);   
    }
}

now I am passing Data from onButtonClick

dbAdapter = new dbAdapter(getApplicationContext());
dbAdapter.insert("XYZ", "XYZ", "xyz.gmail.com", "123456789", "male", "dob", "pune", "username", "password");
Log.e("Sucess","Register");

but getting error like
enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T12:38:10+00:00Added an answer on June 15, 2026 at 12:38 pm

    change

    public dbAdapter(OnClickListener onClickListener) {
            this.context = (Context) onClickListener;
            open();
        }
    

    and dbAdapter = new dbAdapter(this);

    to

    public dbAdapter(Context context) {
            this.context = context;
            open();
        }
    

    and dbAdapter = new dbAdapter(Your_activity.this);

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

while trying to insert data i am getting this error 07-29 18:15:19.909: E/sqlite(863): android.database.sqlite.SQLiteException:
I'm trying to insert some data in my Android SQLite freshly created Database with
I'm trying to insert data into the SQLite database using get EditText, but I
I am trying to insert data from a database into a textarea. I can't
I'm trying to insert data into a database when there is no network, but
I am trying to insert a data into SQLite database using Python. INSERT INTO
I'm trying to insert non-latin data into sqlite database using bind variables using System.Data.SQLite.
I'm trying to insert some data into my SQLite database. But I keeo receiving
Android 2.3.3 static String name = Database; static int version = 1; SQLiteDatabase sqlDB;
I am trying to insert data into my SQLite database. I have imported all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.