Very simple database creation

Put your problem here if it does not fit any of the other categories.

Very simple database creation

Postby solo » Sun Apr 15, 2012 5:08 pm

Hi all,

I am trying to create a database - but I wonder, how can I see that the database really was created?

Main class:
Code: Select all
package com.w3senteret.kaloriteller;

import android.app.Activity;
import android.os.Bundle;

public class KaloritellerActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}


MySQLiteHelper:
Code: Select all
package com.w3senteret.kaloriteller;

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

public class MySQLiteHelper extends SQLiteOpenHelper {
   
   // Database table body profile
   public static final String TABLE_BODY_PROFILE = "body_profile"; // Table name
   public static final String COLUMN_ID = "_id";
   public static final String COLUMN_DATE = "date";
   public static final String COLUMN_MAX_KCAL = "max_kcal";
   public static final String COLUMN_MUSCLES = "muscles";
   public static final String COLUMN_BODY_WEIGHT = "body_weight";
   public static final String COLUMN_FAT_PERCENT_OUTER = "fat_percent_outer";
   public static final String COLUMN_FAT_PERCENT_INNER = "fat_percent_inner";
   public static final String COLUMN_AGE = "age";
   public static final String COLUMN_FLUID = "fluid";

   // Database settings
   private static final String DATABASE_NAME = "caloriecounter.db";
   private static final int DATABASE_VERSION = 1;

   // Database creation SQL statement
   private static final String DATABASE_CREATE = "create table "
         + TABLE_BODY_PROFILE + "( "
         + COLUMN_ID + " integer primary key autoincrement, "
         + COLUMN_DATE + " date, "
         + COLUMN_FAT_PERCENT_OUTER + " int, "
         + COLUMN_BODY_WEIGHT + " int, "
         + COLUMN_MAX_KCAL + " int, "
         + COLUMN_AGE + " int, "
         + COLUMN_FLUID + " int, "
         + COLUMN_FAT_PERCENT_INNER + " int, "
         + COLUMN_MUSCLES + " int"
         + ");";

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

   @Override
   public void onCreate(SQLiteDatabase database) {
      database.execSQL(DATABASE_CREATE);
   }

   @Override
   public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
      Log.w(MySQLiteHelper.class.getName(),
            "Upgrading database from version " + oldVersion + " to "
                  + newVersion + ", which will destroy all old data");
      db.execSQL("DROP TABLE IF EXISTS " + TABLE_BODY_PROFILE);
      onCreate(db);
   }
}
~ Asking if computers can think is like asking if submarines can swim.
User avatar
solo
Junior Developer
Junior Developer
 
Posts: 22
Joined: Fri Mar 25, 2011 9:51 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Google [Bot] and 19 guests