Tuesday, February 28, 2012

Create SQLite Database in Android



[sourcecode language="java"]
package com.my.first;

import android.R.string;
import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;

public class DatabaseActivity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

SQLiteDatabase db = openOrCreateDatabase("MyDB", MODE_PRIVATE, null);
db.execSQL("CREATE TABLE IF NOT EXISTS MyTable (FirstName VARCHAR,LastName VARCHAR,Age INT(3))");
db.execSQL("INSERT INTO MyTable VALUES('Josh','Fedric',23)");

Cursor c = db.rawQuery("SELECT * FROM MyTable", null);
c.moveToFirst();
String msg = c.getString(c.getColumnIndex("FirstName"));
Log.d("Fname",msg);

}
}

[/sourcecode]

No comments:

Post a Comment

How to enable CORS in Laravel 5

https://www.youtube.com/watch?v=PozYTvmgcVE 1. Add middleware php artisan make:middleware Cors return $next($request) ->header('Acces...