1. Are you ready for the Galaxy S20? Here is everything we know so far!

Help with SQL servers

Discussion in 'Android Development' started by jersam515, Dec 29, 2011.

  1. jersam515

    jersam515 Lurker
    Thread Starter

    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. Download the Forums for Android™ app!


      Download

       
Loading...
Similar Threads - Help SQL servers
  1. kylabeardad
    Replies:
    4
    Views:
    294
  2. FranzKafkaYs
    Replies:
    0
    Views:
    140
  3. EvasiveEmanual
    Replies:
    4
    Views:
    501
  4. ChristineDorotheaRickner
    Replies:
    26
    Views:
    620
  5. FingleFangle
    Replies:
    1
    Views:
    604
  6. John9870
    Replies:
    6
    Views:
    370
  7. Gihansurendra
    Replies:
    3
    Views:
    326
  8. Scottv1982
    Replies:
    1
    Views:
    316
  9. tragicallyblazed
    Replies:
    4
    Views:
    481
  10. anna79
    Replies:
    1
    Views:
    342

Share This Page

Loading...