Working with the SQLite-Database - Cursors

Basic Tutorials concerning: GUI, Views, Activites, XML, Layouts, Intents, ...

Android database concept

Postby nbagade » Fri Nov 20, 2009 8:14 am

Hi plusminus,

I am creating mobile application where I need to take the vaues from Database.

Actually I am new to android sdk.I have work experience of Dot net technology and sql server databse in creating windows desktop application.

where there will be one centrailize databse server and u can access the data from our application through sqlconnection by using sql query or storeprocedure.

Is this concept is there in android sqllite databse.

can i create comman databse for all my application.?

If I create the databse where it will save physically.
How to access the data from android code.


please guide me .

Thanks a Lot in Advance.
Nbagade
nbagade
Experienced Developer
Experienced Developer
 
Posts: 57
Joined: Fri Nov 20, 2009 7:49 am
Location: India

Top

Help

Postby nbagade » Tue Dec 01, 2009 10:59 am

I am waiting for help sir.
nbagade
Experienced Developer
Experienced Developer
 
Posts: 57
Joined: Fri Nov 20, 2009 7:49 am
Location: India

Re: Android database concept

Postby achie1266 » Thu Dec 03, 2009 8:32 pm

nbagade wrote:Hi plusminus,

I am creating mobile application where I need to take the vaues from Database.

Actually I am new to android sdk.I have work experience of Dot net technology and sql server databse in creating windows desktop application.

where there will be one centrailize databse server and u can access the data from our application through sqlconnection by using sql query or storeprocedure.

Is this concept is there in android sqllite databse.

can i create comman databse for all my application.?

If I create the databse where it will save physically.
How to access the data from android code.


please guide me .

Thanks a Lot in Advance.
Nbagade


No sqlite is not a server.
You do not need stored procedures.You can directly query your database.
You might want to look at the notepad tutorial on android to get an idea of how database stuff works in android.

http://developer.android.com/guide/tuto ... index.html
achie
User avatar
achie1266
Senior Developer
Senior Developer
 
Posts: 184
Joined: Mon Nov 09, 2009 10:56 pm
Location: Denver

Thank you So..much

Postby vasuravada » Mon Jan 04, 2010 10:27 pm

Hi...paul...

This post is really very helpful in understanding the functionality of SQLite databases
in an Android application.....I was corrected my all mistakes by looking at the older posts by so
many frndzzz.....

Thank you so much to all buddies ...... :)
Don't run behind the success...Try for excellence success will automatically follows you...
vasuravada
Freshman
Freshman
 
Posts: 2
Joined: Mon Jan 04, 2010 10:16 pm
Location: Hyderabad

Postby dpace32 » Sat Mar 27, 2010 9:09 pm

Hello -

For some reason I can never execute the full source code. I download the ZIP, import it into Eclipse but when I try to run this one (for example) I get a list of errors such as the attached list. Do you know what the issue could be? I edited the library to point to the correct SDK version. Any help on this would be greatly appreciated.

Thanks,
-Adam
Attachments
test.png
test.png (42.92 KiB) Viewed 1142 times
dpace32
Once Poster
Once Poster
 
Posts: 1
Joined: Sat Mar 27, 2010 9:04 pm

Postby hendra40 » Sun Apr 04, 2010 12:56 am

Hello, everyone.
I am beginner in the android programming.

Two days ago, I face same problem about connecting to database in android.
But now, I have found solution code to connect to database in android.

Please try this code ( You only create a new project and copy this code in .java and change the package name ) :
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. package com.Android.Beta; //Please change with your package name
  3.  
  4.  
  5.  
  6. import android.app.Activity;
  7.  
  8. import android.database.Cursor;
  9.  
  10. import android.database.sqlite.SQLiteDatabase;
  11.  
  12. import android.os.Bundle;
  13.  
  14. import android.util.Log;
  15.  
  16. import android.widget.TextView;
  17.  
  18.  
  19.  
  20. public class insert extends Activity {  // change class name too
  21.  
  22.  /** Called when the activity is first created. */
  23.  
  24.  @Override
  25.  
  26.  public void onCreate(Bundle savedInstanceState) {
  27.  
  28.   super.onCreate(savedInstanceState);
  29.  
  30.  
  31.  
  32.   SQLiteDatabase myDB= null;
  33.  
  34.   String TableName = "dictionary";
  35.  
  36.  
  37.  
  38.   String Data = "";
  39.  
  40.  
  41.  
  42.   /* Create a Database. */
  43.  
  44.   try {
  45.  
  46.    myDB = this.openOrCreateDatabase("handwriting", MODE_PRIVATE, null);
  47.  
  48.  
  49.  
  50.    /* Create a Table in the Database. */
  51.  
  52.    myDB.execSQL("CREATE TABLE IF NOT EXISTS "
  53.  
  54.      + TableName
  55.  
  56.      + " (japan_word VARCHAR, english_word VARCHAR);");
  57.  
  58.  
  59.  
  60.    /* Insert data to a Table*/
  61.  
  62.    myDB.execSQL("INSERT INTO "
  63.  
  64.      + TableName
  65.  
  66.      + " (japan_word, english_word)"
  67.  
  68.      + " VALUES ('konpyuta ', 'computer');");
  69.  
  70.  
  71.  
  72.    /*retrieve data from database */
  73.  
  74.    Cursor c = myDB.rawQuery("SELECT * FROM " + TableName , null);
  75.  
  76.  
  77.  
  78.    int Column1 = c.getColumnIndex("japan_word");
  79.  
  80.    int Column2 = c.getColumnIndex("english_word");
  81.  
  82.  
  83.  
  84.    // Check if our result was valid.
  85.  
  86.    c.moveToFirst();
  87.  
  88.    if (c != null) {
  89.  
  90.     // Loop through all Results
  91.  
  92.     do {
  93.  
  94.      String word1 = c.getString(Column1);
  95.  
  96.      String word2 = c.getString(Column2);
  97.  
  98.      Data =Data +word1+"/"+word2+"\n";
  99.  
  100.     }while(c.moveToNext());
  101.  
  102.    }
  103.  
  104.    TextView tv = new TextView(this);
  105.  
  106.    tv.setText(Data);
  107.  
  108.  
  109.  
  110.    setContentView(tv);
  111.  
  112.   }
  113.  
  114.   catch(Exception e) {
  115.  
  116.    Log.e("Error", "Error", e);
  117.  
  118.   } finally {
  119.  
  120.    if (myDB != null)
  121.  
  122.     myDB.close();
  123.  
  124.   }
  125.  
  126.  }
  127.  
  128. }
  129.  
  130.  
  131.  
  132.  
Parsed in 0.166 seconds, using GeSHi 1.0.8.4


I hope this code help you.
I use eclipse 3.5 and Android 2.1
hendra40
Freshman
Freshman
 
Posts: 2
Joined: Sun Apr 04, 2010 12:42 am

Top

Postby Normano » Thu Apr 08, 2010 8:22 pm

Do anyone know how to update the list on change on other activity?
I've tried
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public void onResume(Bundle icicle) {
  2.  
  3.                 c.requery();
  4.  
  5.     }
Parsed in 0.135 seconds, using GeSHi 1.0.8.4

But that dosen't work :(
Normano
Once Poster
Once Poster
 
Posts: 1
Joined: Thu Apr 08, 2010 8:19 pm

Re: Working with the SQLite-Database - Cursors

Postby MorbidDestiny » Thu May 20, 2010 12:13 pm

Hi!

Is it possible to store the Database on a SDCard?

If so, could you please help me in making it?

Thanks
MorbidDestiny
Junior Developer
Junior Developer
 
Posts: 16
Joined: Fri Mar 26, 2010 4:56 pm

Top
Previous

Return to Novice Tutorials

Who is online

Users browsing this forum: pskink and 2 guests