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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:28:20+00:00 2026-05-27T19:28:20+00:00

I did the notepad tutorials and my SQL server is a modified version of

  • 0

I did the notepad tutorials and my SQL server is a modified version of that. For some reason my app is not writing to it correctly. Any help would be greatly appreciated. I dont understand what part of the code is wrong.

    package com.drawing;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class NotesDbAdapter {

 public static final String KEY_ROWID = "_id";
public static final String KEY_X = "x";
public static final String KEY_Y = "y";
public static final String KEY_Size = "size";
private static final String TAG = "NotesDbAdapter";
private DatabaseHelper mDbHelper;
private SQLiteDatabase mDb;
private static final String DATABASE_NAME = "data";
private static final String DATABASE_TABLE = "notes";
private static final int DATABASE_VERSION = 2;
private static final String DATABASE_CREATE =
          " create table " +  DATABASE_TABLE  + " ("
         + KEY_ROWID + " integer primary key autoincrement,  "
         + KEY_X + " text not null, "
         + KEY_Y + " text not null, "
         + KEY_Size + " text not null);"; 

    private final Context mCtx;

    private static class DatabaseHelper extends SQLiteOpenHelper {

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


            @Override
            public void onCreate(SQLiteDatabase db) {
                try {
                    db.execSQL(DATABASE_CREATE);  
                } catch (Exception e) {
                    Log.e("dbAdapter", e.getMessage().toString());
                }
            }

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
            Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
                    + newVersion + ", which will destroy all old data");
            db.execSQL("DROP TABLE IF EXISTS notes");
            onCreate(db); 
        }

    }

    public NotesDbAdapter(Context ctx) {
        this.mCtx = ctx;
    }

    public NotesDbAdapter open() throws SQLException {
        mDbHelper = new DatabaseHelper(mCtx);
        mDb = mDbHelper.getWritableDatabase();
        return this;
    }

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


    public long createNote(float f, float g, int size) {
        ContentValues initialValues = new ContentValues();
        initialValues.put(KEY_X, f);
        initialValues.put(KEY_Y, g);
        initialValues.put(KEY_Size, size);
        return mDb.insert(DATABASE_TABLE, null, initialValues);
    }

    public boolean deleteNote(long rowId) {

        return mDb.delete(DATABASE_TABLE, KEY_ROWID + "=" + rowId, null) > 0;
    }


    public Cursor fetchAllNotes() {

        return mDb.query(DATABASE_TABLE, new String[] {KEY_ROWID, KEY_X,KEY_Y,KEY_Size}, null, null, null, null, null);
    }

    public Cursor fetchNote(long rowId) throws SQLException {

        Cursor mCursor =

            mDb.query(true, DATABASE_TABLE, new String[] {KEY_ROWID, KEY_X,KEY_Y,KEY_Size}, KEY_ROWID + "=" + rowId, null,
                    null, null, null, null);
        if (mCursor != null) {
            mCursor.moveToFirst();
        }
        return mCursor;

    }

    public boolean updateNote(long rowId, int x, int y, int size) {
        ContentValues args = new ContentValues();
        args.put(KEY_X, x);
        args.put(KEY_Y, y);
        args.put(KEY_Size, size);
        return mDb.update(DATABASE_TABLE, args, KEY_ROWID + "=" + rowId, null) > 0;
    }
}
  • 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-05-27T19:28:21+00:00Added an answer on May 27, 2026 at 7:28 pm

    I think your problem is initiated here:

    public static final String KEY_ROWID = "_id";     
    public static final String KEY_X = "_id";     
    public static final String KEY_Y = "_id";     
    public static final String KEY_Size = "_id"; 
    

    I would guess it should be more like in the question I link to:

    public static final String KEY_BOOK = "book"; 
    public static final String KEY_AUTHOR = "author"; 
    public static final String KEY_ISBN = "isbn"; 
    public static final String KEY_RATING = "rating"; 
    public static final String KEY_ROWID = "_id"; 
    

    Second, your table creation also seems wrong:

    private static final String DATABASE_CREATE = 
                " create table " +  DATABASE_TABLE  + " (" 
                         + KEY_ROWID + " integer primary key autoincrement,  "
                         + KEY_X + " integer primary key autoincrement, "
                         + KEY_Y + " integer primary key autoincrement, "
                         + KEY_Size + " integer primary key autoincrement, ";
    

    You have created all fields as primary key and autoincrement – that doesn’t really make sense. Again looking at the other question:

    private static final String DATABASE_CREATE =
          " create table " +  DATABASE_TABLE  + " ("
         + KEY_ROWID + " integer primary key autoincrement,  "
         + KEY_AUTHOR + " text not null, "
         + KEY_BOOK + " text not null, "
         + KEY_ISBN + " text not null, "
         + KEY_RATING + " text not null);"; 
    

    This makes much more sense.

    Please take a closer look at the question below – and re-read the tutorials you have started with.

    I keep getting the SQLException error with this

    The question here may have problems, but seem to identify the columns properly (which is where you seem to have problems). The answers go through some other steps – and I recommend that you take a look at the ‘Related’ suggestions here on the right side of your own question. You may find more pointers to lead you in the right direction.

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

Sidebar

Related Questions

Did anyone try that feature and has some feedback? Or Does anyone know some
Did not receive any exact answer, thus I would have to accept mine ...
Did you ever had a bug in your code, you could not resolve? I
Did you ever use Oracle auditing features on a production db? How did that
Did you know that : Map<Object,Object> m1 = new HashMap<Object, Object>(); Map<Object,Object> m2 =
Did anyone try to read programmatically an Alibre Design CAD file? I see that
I am writing C# application that need to print data to POS STAR printer
Did anyone face a problem of putting buttons (or any other widgets) on the
Did defaultdict's become not marshal'able as of Python 2.6? The following works under 2.5,
I KNOW I did this in WP7 (not WP7.1) and I can't figure out

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.