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

  • Home
  • SEARCH
  • 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 8759127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:43:23+00:00 2026-06-13T14:43:23+00:00

Possible Duplicate: Android:How to write to SQL database I enter data into a form

  • 0

Possible Duplicate:
Android:How to write to SQL database

I enter data into a form and on press of the button the strings should be sent to the database and I have a dialog box to open if writing was successful however, I’m getting no response.

Edit: I identified the error as ” AUTOINCREMENT is only allowed on an INTEGER PRIMARY KEY”
However my primary key is an integer?

public class AddCourse extends Activity implements OnClickListener {

Button sqlAddModule;
EditText sqlModuleCode, sqlModuleName, sqlModuleStart, sqlModuleEnd, sqlModuleLocation, sqlModuleComments;
 @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.add_course);

        sqlAddModule= (Button)findViewById(R.id.addToDatabase);
        sqlModuleCode = (EditText)findViewById(R.id.labelEditModuleCode);
        sqlModuleName = (EditText)findViewById(R.id.labelEditModuleFull);
        sqlModuleLocation = (EditText)findViewById(R.id.labelEditModuleLocation);
        sqlModuleComments = (EditText)findViewById(R.id.labelEditModuleComments);

        sqlAddModule.setOnClickListener(this);
 }

        public void onClick (View addModuleButton) 
        {
            boolean didItWork = true;
            try{
            String moduleCode = sqlModuleCode.getText().toString();
            String moduleName = sqlModuleName.getText().toString();
            String moduleLocation = sqlModuleLocation.getText().toString();
            String moduleComments = sqlModuleComments.getText().toString();

            database entry = new database(AddCourse.this);
            entry.open();
            entry.createEntry(moduleCode, moduleName,moduleLocation, moduleComments);
            entry.close();

            }catch(Exception e){
                didItWork = false;
            }finally{ if(didItWork){
                Dialog d = new Dialog(this) ;
                d.setTitle("BooYa!");
                TextView tv = new TextView(this);
                tv.setText("Success");
                d.setContentView(tv);
                d.show();
            }


            }

            finish();

        }    

}

SQL Class

public class database {

    public static final String KEY_ROWID = "_id";
    public static final String KEY_MODULECODE = "module_code";
    public static final String KEY_MODULENAME = "module_name";
    public static final String KEY_MODULETYPE = "module_type";
    public static final String KEY_MODULEDAY = "module_day";
    public static final String KEY_MODULESTART = "module_start";
    public static final String KEY_MODULEEND = "module_end";
    public static final String KEY_MODULELOCATION = "module_location";
    public static final String KEY_MODULECOMMENTS = "module_comments";

    private static final String DATABASE_NAME = "module_database";
    private static final String DATABASE_TABLE = "my_modules";
    private static final int DATABASE_VERSION = 1;

    private DbHelper myHelper;
    private final Context myContext;
    private SQLiteDatabase moduleDatabase;

    private static class DbHelper extends SQLiteOpenHelper {

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

        }

        @Override
        public void onCreate(SQLiteDatabase db) {
            db.execSQL("CREATE TABLE " + DATABASE_TABLE + " (" +
                        KEY_ROWID + " INTERGER PRIMARY KEY AUTOINCREMENT, " +
                        KEY_MODULECODE + " TEXT NOT NULL, " +
                        KEY_MODULENAME + " TEXT NOT NULL, " +
                        KEY_MODULELOCATION + " TEXT NOT NULL, " +
                        KEY_MODULECOMMENTS + " TEXT NOT NULL,);"
                    );

        }

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
            // TODO Auto-generated method stub
            db.execSQL("DROP TABEL IF EXISTS " + DATABASE_TABLE);
            onCreate(db);

        }


    }

    public database(Context c){
        myContext = c;
    }

    public  database open()throws SQLException{
        myHelper = new DbHelper(myContext);
        moduleDatabase = myHelper.getWritableDatabase();
        return this;
    }

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

    public long createEntry(String moduleCode, String moduleName,  String moduleLocation, String moduleComments) {
        ContentValues cv = new ContentValues();
        cv.put(KEY_MODULECODE,moduleCode);
        cv.put(KEY_MODULENAME,moduleName);
        cv.put(KEY_MODULELOCATION,moduleLocation);
        cv.put(KEY_MODULECOMMENTS,moduleComments);
        return moduleDatabase.insert(DATABASE_TABLE,null,cv);
        // TODO Auto-generated method stub

    }

}
  • 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-13T14:43:24+00:00Added an answer on June 13, 2026 at 2:43 pm

    There’s a typo in your database class:
    " INTERGER PRIMARY KEY AUTOINCREMENT, "
    that is not the correct spelling of “INTEGER”, as you probably already know. Also, take note of db.execSQL("DROP TABEL IF EXISTS " + DATABASE_TABLE);

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

Sidebar

Related Questions

Possible Duplicate: Android access to remote SQL database I am going to make android
Possible Duplicate: Android Button: set onClick background image change with XML? I need that
Possible Duplicate: Android: How to create slide (on/off) button I want to create sliding
Possible Duplicate: Android error - close() was never explicitly called on database I have
Possible Duplicate: Android ListView with delete button android Listview button Okay .. I will
Possible Duplicate: How to access an existing sqlite database in Android? I've been searching
Possible Duplicate: Android Button Tooltip Is there any way to construct a view where
Possible Duplicate: Standard Android Button with a different color I have 1 problem -
Possible Duplicate: sqlite example program in android I need to open a database where
Possible Duplicate: Android HttpClient and HTTPS I want to write app on Android which

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.