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 8673487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:28:18+00:00 2026-06-12T19:28:18+00:00

I am tring to add new record in my sqlite database. I am not

  • 0

I am tring to add new record in my sqlite database. I am not getting any error but also not seen any kind of record in database when i see database using sqlite manager
following is the code which i have written. plz help me to get out of this problem.

following is my code of database handler ..

enter code here
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
import android.widget.Toast;

public class DatabaseHandler extends SQLiteOpenHelper
{

private static final int DATABASE_VERSON=1;
private static final String DATABASE_NAME="Info_manager";
private static final String TABLE_DETAILS = "info_detail";

// Contacts Table Columns names
private static final String KEY_ID = "id";
private static final String KEY_FNAME = "f_name";
private static final String KEY_LNAME = "l_name";
private static final String KEY_PH_NO = "c_num";
private static final String KEY_EMAIL = "e_mail";



public DatabaseHandler(Context context) 
{
    super(context,null , null, 1);
}

@Override
public void onCreate(SQLiteDatabase db) 
{
    //db = this.getWritableDatabase();
    ///System.out.println("----333------");
    String CREATE_DETAILS_TABLE = "CREATE TABLE " + TABLE_DETAILS 
    + "("
    + KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + KEY_FNAME + " TEXT," + KEY_LNAME + " TEXT," + KEY_PH_NO + " TEXT," + KEY_EMAIL + " TEXT " + ")";

    db.execSQL(CREATE_DETAILS_TABLE);
    ///System.out.println("----444------");
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) 
{
    // Drop older table if existed
    db.execSQL("DROP TABLE IF EXISTS " + TABLE_DETAILS);
    // Create tables again
    onCreate(db);

}


 // Adding new contact
void addContact(Contact contact) 
{
    SQLiteDatabase db = this.getWritableDatabase();
   // ContentValues values = new ContentValues();

    String sql;
    sql = "INSERT INTO info_detail (f_name, l_name, c_num, e_mail) " + 
    "VALUES ('" + contact.getfName().toString() + "', '" + contact.getlName().toString() + "', '" + contact.getContactNumber().toString()+ "', '" + contact.getEmailAddress().toString() +"' )";

    db.execSQL(sql);

    /*values.put(KEY_FNAME, contact.getfName());
    values.put(KEY_LNAME, contact.getlName());
    values.put(KEY_PH_NO, contact.getContactNumber());
    values.put(KEY_EMAIL, contact.getEmailAddress());*/
    // Inserting Row
    System.out.print("----inserting----");
    //db.insert(TABLE_DETAILS, null, values);

    System.out.print("----inserted----");
    db.close(); 
}

}

and following is the activity from which i called handler

public class SQLitelActivity extends Activity implements OnClickListener 
{

EditText fname,lname,con_num,email_adr;
Button savebtn,viewbtn;
DatabaseHandler db;
//SQLiteDatabase db;
@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sqlitel);

    fname=(EditText)findViewById(R.id.fname);
    lname=(EditText)findViewById(R.id.lname);
    con_num=(EditText)findViewById(R.id.cnumber);
    email_adr=(EditText)findViewById(R.id.email);

    savebtn=(Button)findViewById(R.id.save);
    viewbtn=(Button)findViewById(R.id.view);

    db=new DatabaseHandler(this);

    savebtn.setOnClickListener(new OnClickListener() 
    {
        @Override
        public void onClick(View v) 
        {
            //System.out.println("----111------");
            db.addContact(new Contact(fname.getText().toString()
                    , lname.getText().toString(),con_num.getText().toString(),email_adr.getText().toString()));
        //  System.out.println("----222------");
        }
    }
    );
  • 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-12T19:28:19+00:00Added an answer on June 12, 2026 at 7:28 pm

    here is code with modification,

    public DatabaseHandler(Context context) {
            super(context, DATABASE_NAME, null, DATABASE_VERSION);
        }
    

    you miss Database Name here in super constructor.

    And i am using following METHOD to add contact to database,

        // Adding new contact
        void addContact(Contact contact) {
            SQLiteDatabase db = this.getWritableDatabase();
    
            ContentValues values = new ContentValues();
            values.put(KEY_FNAME, contact.getfName().toString()); // Contact First Name
            values.put(KEY_LNAME, contact.getlName().toString()); // Contact Last Name
            values.put(KEY_PH_NO, contact.getContactNumber().toString()); // Contact Number
            values.put(KEY_EMAIL, contact.getEmailAddress().toString() ); // Contact Email
    
            // Inserting Row
            db.insert(TABLE_CONTACTS, null, values);
            db.close(); // Closing database connection
        }
    

    i hope this will help you. Thanks.

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

Sidebar

Related Questions

I want to add a new item (Cheese) to an sqlite table but only
i am trying to display the 'add new record' display in jqgrid but it
I am trying to add a new record to my internal table and this
Im new to asp.net mvc. I'm trying add new model class but it got
I am trying to add a new column into an SQLiteDatabase but every time
Im trying to add an element to a database and then return a new
I am trying to add a new record in a table with the following
I'm trying to write a generic C# function to add a new record to
I'm new to databases and am trying to add a new record using SQL.
I am trying to use Formalchemy to add a new record to my SQLAlchemy

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.