hii..i am new to android..i am developing an android application on platform 2.1..
There are two textbox: one for Name and other for entering job.I want the values should be taken from the 2 textboxes editText1 and editText2 and inserted in my database whenever a user clicks the button.Please help im stuck in this part.
my code is creating the table, but values are not being inserted into it.

here are my two classes:

package test.db.help;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

public class DbHelper extends SQLiteOpenHelper {
    public static final String db_name = "mydb.db";
    public static final int db_version = 1;
    public final String TABLE = "test";

    public  final String C_Name = "Name";
    public final String C_job = "Job";

    public DbHelper(Context context, String db_name, CursorFactory factory,
            int version) {
        super(context, db_name, null, db_version);
        // TODO Auto-generated constructor stub

    public void onCreate(SQLiteDatabase db) {
        // TODO Auto-generated method stub

        String sql = String.format(
                "create table %s ( %s TEXT, %s TEXT )",
                TABLE, C_Name, C_job);



    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // TODO Auto-generated method stub




package test.db.help;

import android.app.Activity;
import android.content.ContentValues;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class TestActivity extends Activity implements OnClickListener {
    EditText Name,Job;
    Button b;
    DbHelper obj;
    SQLiteDatabase db;
    public static final String db_name = "mydb.db";
    public static final int db_version = 1;
    ContentValues val; 

    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {


        Name=(EditText) findViewById(R.id.editText1);
        Job = (EditText) findViewById(R.id.editText2);

        obj=new DbHelper(TestActivity.this,db_name , null, db_version);

    public void onClick(View v) {
        // TODO Auto-generated method stub
        val=new ContentValues();

        db.insert(obj.TABLE, null, val);

You are missing ContentProvider and other stuff. Read this tutorial

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.