Studyon Minte9.com
Android




Table



1) Create

        %--- MySQLiteHelper.java

	package com.example.myapp;
	import android.content.Context;
	import android.database.sqlite.SQLiteDatabase;
	import android.database.sqlite.SQLiteOpenHelper;

	public class MySQLiteHelper extends SQLiteOpenHelper {
		
		public static final String DB_NAME = "comments.db";
		public static final int DB_VERSION = 1;

		public MySQLiteHelper(Context context) {
			super(context, DB_NAME, null, DB_VERSION);
		}
		
		@Override
		public void onCreate(SQLiteDatabase db) {
			
			/*--- LOOK HERE ---*/

			String sql = "CREATE TABLE comments (" 
					+ "_id INTEGER PRIMARY KEY AUTOINCREMENT, "	
					+ "comment TEXT NOT NULL"
					+ ")";
			db.execSQL(sql);
		}
		
		@Override
		public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {}
	}


	%--- MainActivity.java

	package com.example.myapp;
	import android.app.Activity;
	import android.database.Cursor;
	import android.database.sqlite.SQLiteDatabase;
	import android.os.Bundle;
	import android.widget.Toast;

	public class MainActivity extends Activity {

	    @Override
	    protected void onCreate(Bundle state) {
			super.onCreate(state);
			setContentView(R.layout.activity_main);

			SQLiteDatabase db = new MySQLiteHelper(this).getReadableDatabase();
			
			/*--- LOOK HERE ---*/

			//Check if table exists
			String sql = "SELECT DISTINCT tbl_name FROM sqlite_master " 
                               + "WHERE tbl_name = 'comments'";
			Cursor cursor = db.rawQuery(sql, null);
			if (cursor != null)
				Toast.makeText(getApplicationContext(), 
                                        "Table exists" + db.getVersion(), Toast.LENGTH_LONG).show();
		}
	}


http://www.vogella.com/articles/AndroidSQLite/article.html#databasetutorial_database
http://stackoverflow.com/questions/3058909/how-does-one-check-if-a-table-exists-in-an-android-sqlite-database