It looks like you are trying to use an anddev example there (http://
www.anddev.org/working_with_the_sqlite-database_-_cursors-t319.html),
but you have random stuff commented out, and that example says at the
top of the page "Compatible for SDK version m3-xxx or older".

If you are trying to adapt that to learn how to use a DB, well, that I
get, but try a more up to date example to begin with. The NotePad
tutorial uses a database, for example:  
http://code.google.com/android/samples/NotePad/index.html.
Even though NotePad is creating a Provider, you don't have to do that
to see what they are doing with the DB there (and SQLiteOpenHelper is
your friend, Provider or not).




On Nov 24, 4:41 am, Rahul <[EMAIL PROTECTED]> wrote:
> hi
> I am beginner for the android .now i createdone application in
> androidwhich is to connecting the database and showing the datain the
> screen but i hava lot of problem 1) connection is made but the data is
> not showing in emulator
> i want to inset update delete the data from database but i have
> stopped in the startig point to take the data from database and show
> on emulator plz help me
> i have sent amy code if  any mistake in the code plz tel me or give me
> some perfect code to give me those answer
>  package com.DataBaseWork;
>
> import java.util.ArrayList;
>
> import android.app.ListActivity;
> import android.database.Cursor;
> import android.database.SQLException;
> import android.database.sqlite.SQLiteDatabase;
> import android.os.Bundle;
> import android.util.Log;
> import android.widget.ArrayAdapter;
> import android.widget.EditText;
>
> public class DataBaseWork extends ListActivity {
>
>         private final String MY_DATABASE_NAME = "myCoolDB_2";
>         private final String MY_DATABASE_TABLE = "Users";
>
>         /** Called when the activity is first created. */
>         @Override
>         public void onCreate(Bundle icicle) {
>                 super.onCreate(icicle);
>                 EditText et = new EditText(this);
>                 et.setSelection(et.getText().length());
>                 /* Will hold the 'Output' we want to display at the end. */
>                 ArrayList<String> results = new ArrayList<String>();
>                 SQLiteDatabase myDB = null;
>                 try {
>                         myDB =this.openOrCreateDatabase
> (MY_DATABASE_NAME,MODE_WORLD_READABLE,null);
>                         /* Create the Database (no Errors if it already 
> exists) */
>                         //this.createDatabase(MY_DATABASE_NAME, 1, 
> MODE_PRIVATE, null);
>                         /* Open the DB and remember it */
>                         //myDB = this.openDatabase(MY_DATABASE_NAME, null);
>
>                         /* Create a Table in the Database. */
>                         myDB.execSQL("CREATE TABLE IF NOT EXISTS "
>                                                         + MY_DATABASE_TABLE
>                                                         + " (LastName 
> VARCHAR, FirstName VARCHAR,"
>                                                         + " Country VARCHAR, 
> Age INT(3));");
>
>                         myDB.execSQL("INSERT INTO "
>                                                         + MY_DATABASE_TABLE
>                                                         + " (LastName, 
> FirstName, Country, Age)"
>                                                         + " VALUES 
> ('Gramlich', 'Nicolas', 'Germany', 20);");
>                         myDB.execSQL("INSERT INTO "
>                                                         + MY_DATABASE_TABLE
>                                                         + " (LastName, 
> FirstName, Country, Age)"
>                                                         + " VALUES ('Doe', 
> 'John', 'US', 34);");
>
>                         /* Query for some results with Selection and 
> Projection. */
>                         /*Cursor c = myDB.query(true, "SELECT FirstName,Age" +
>                                                                 " FROM " + 
> MY_DATABASE_TABLE
>                                                                 + " WHERE Age 
> > 10 LIMIT 7;",
>                                                 null,null,null,null,null, 
> null, MY_DATABASE_NAME);*/
>                         /*Cursor c = myDB.query(MY_DATABASE_TABLE, new 
> String[]
>                         {"FirstName","Age"},null,null,null,null,null);*/
>
>                         Cursor c = myDB.rawQuery("SELECT FirstName,Age" +
>                     " FROM " + MY_DATABASE_TABLE ,null);
>
>                         //Log.i(tag,"value seleted ");
>
>                         int firstNameColumn = c.getColumnIndex("FirstName");
>                         int ageColumn = c.getColumnIndex("Age");
>
>                         if (c != null) {
>                                 if (c.isFirst()) {
>                                         int i = 0;
>
>                                         do {
>                                                 i++;
>                                                 String firstName = 
> c.getString(firstNameColumn);
>                                                 int age = c.getInt(ageColumn);
>                                                 String ageColumName = 
> c.getColumnName(ageColumn);
>                                                 results.add("" + i + ": " + 
> firstName
>                                                 + " (" + ageColumName + ": " 
> + age + ")");
>                                                 //c.moveToFirst();
>                                         } while (c.moveToFirst());
>                                 }
>                         }
>                 } catch (SQLException e)
>                 {
>                         Log.e ("Exception on query:-", e.toString());
>
>                 } finally {
>                         if (myDB != null)
>                                 myDB.close();
>                 }
>
>                 this.setListAdapter(new ArrayAdapter<String>(this,
>                                 android.R.layout.simple_list_item_1, 
> results));
>         }
>
> }
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to