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: 58
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: 58
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
Master Developer
Master Developer
 
Posts: 223
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 5345 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.039 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.030 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

Re: Working with the SQLite-Database - Cursors

Postby karthik8687 » Fri Sep 03, 2010 9:31 am

hi
thanks for the tutorial :D .. i really understood the concepts.. basically i'm not able to execute it... problem with SDK version i guess... can i expect some changes in source code which make it compatible with newer version...
I'm not getting where all I need to make changes....


Another request.. how to add data to SQLite database using checkbox???


please help me..
karthik8687
Once Poster
Once Poster
 
Posts: 1
Joined: Fri Sep 03, 2010 7:41 am

Re: Working with the SQLite-Database - Cursors

Postby farhan » Sun Oct 24, 2010 6:10 pm

http://mfarhan133.wordpress.com/2010/10 ... r-android/

Its an excellent tutorial for android DB CRUD with
COMPLETE SOURCE CODE
farhan
Freshman
Freshman
 
Posts: 2
Joined: Sun Oct 24, 2010 5:59 pm

Re: Working with the SQLite-Database - Cursors

Postby kumar1234567 » Tue Nov 02, 2010 1:47 pm

Hello sir,

I had a doubt in Android SQLite database connectivity.

First.java
I had create a activity class that have UI components such as (TextView & EditView for UserName) and (TextView & EditView for Password) and button (Login).

SampleSql.java
I had created sqlite database and one table with attribute like usarname and password in varchar and then i insert five people account.

I dont know how to connect these two classes and when i enter the some value in username and password, it want to check in database, when the both the value are correct it goes to another page by using intent.
My question is how to connect the sqlite database with activity class. I know this very simple question in java but i'm not familiar with sqlite database.
Please suggest me any ideas or send me a code,.

Thanks in advance,
kumar.
kumar1234567
Freshman
Freshman
 
Posts: 3
Joined: Tue Nov 02, 2010 7:02 am

Re:

Postby ericharlow » Tue Nov 02, 2010 8:13 pm

Normano wrote: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.                 c.requery();
  3.     }
Parsed in 0.033 seconds, using GeSHi 1.0.8.4

But that dosen't work :(


yes. All you need to do is add a line of code like this.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public void onResume(Bundle icicle) {
  2.                 c.requery();
  3.                 getListView().invalidateViews();
  4.     }
Parsed in 0.035 seconds, using GeSHi 1.0.8.4
ericharlow
Freshman
Freshman
 
Posts: 4
Joined: Fri Sep 24, 2010 5:05 pm

Re: Working with the SQLite-Database - Cursors

Postby kumar1234567 » Tue Nov 09, 2010 11:16 am

hello sir,

i created database and tables and inserted some values. I want to retrieve values whenever user enter some value in the editview textbox.

It check the value whether it is in database and if it correct i want to go to next page.

could anyone please give any sample code or suggest ideas..?

thanks in advance
kumar.
kumar1234567
Freshman
Freshman
 
Posts: 3
Joined: Tue Nov 02, 2010 7:02 am

Re: Working with the SQLite-Database - Cursors

Postby david.treshansky » Sat Dec 04, 2010 7:11 pm

Plusminus,

I am a novice (but again this is a novice forum). How do I take the attached code and import it into a project in Eclipse so I can learn from it? Thanks in advance for your assistance.
david.treshansky
Freshman
Freshman
 
Posts: 3
Joined: Thu Dec 02, 2010 3:16 pm

Re: Working with the SQLite-Database - Cursors

Postby sheikh.aman » Tue Jan 25, 2011 9:06 am

    - Just click on the ZIP file attached with plusminus's message.
    - Save it somewhere.
    - Open your eclipse, File>import
    - A dialogue box will appear giving few options. Select "Existing Projects into workspace" from "General" tab
    - In the next dialogue box, select the "archive" radio button, and "browse" for the ZIP that you just downloaded.
    - Once you have located it, you'll see that Eclipse has filled all the other fields.
    - Now, click on "finish" button.
    - Voila! your project is imported!
Impossible is Nothing
User avatar
sheikh.aman
Developer
Developer
 
Posts: 40
Joined: Sat Mar 20, 2010 7:52 am

Top
PreviousNext

Return to Novice Tutorials

Who is online

Users browsing this forum: No registered users and 5 guests