Hi, I am very new to SQLite, i referred some books regarding coding in
SQLite n went straight for coding
But while i run my simple code i am getting error "the application has
stopped unexpectadly" (particularly in the line create table)
please tell me where exactly is the error n where i hav to modify the code
package com.android;
import android.app.Activity;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.widget.EditText;
public class DatabaseWork extends Activity {
private EditText et;
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
et=(EditText)findViewById(R.id.EditText01);
tryThis();
}
public void tryThis()
{
final String DATABASE_NAME="myDatabse.db";
final String DATABASE_TABLE="myTable";
final int DATABASE_VERSION=1;
final String COL_NAME="name";
final String COL_ID="id";
SQLiteDatabase db;
db=openOrCreateDatabase(DATABASE_NAME, 0, null);
db.execSQL("create table myTable (id integer primary key, name text not
null);");
db.execSQL("insert into myTable values (1, \"Bharath\");");
db.execSQL("insert into myTable values (2, \"Abhijith\");");
Cursor c=db.query(DATABASE_TABLE, new String[] { COL_ID,COL_NAME}, null,
null, null, null, null);
int idCol=c.getColumnIndex(COL_ID);
int nameCol=c.getColumnIndex(COL_NAME);
String s=null;
while(true)
{
String name=c.getString(nameCol);
s=s+" "+name;
if(c.isLast())
{
break;
}
c.moveToNext();
}
et.setText(s);
db.close();
}
}
--
Bharath B.G.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---