Working with the SQLite-Database - Cursors

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

date print on mobile screen

Postby dhaiwat » Mon Feb 23, 2009 12:15 pm

hello friend

i am new with android

i want to print current date on mobile screen

what i do.

i want to take today's date from sqlite query

any one help me how i get date in textview from query result..
dhaiwat
Developer
Developer
 
Posts: 28
Joined: Tue Feb 10, 2009 6:49 am

Top

database query problem

Postby dhaiwat » Tue Feb 24, 2009 11:47 am

hello friends

i have two table

1. Student --- fields (RollNo,StudentName)

2. Marks ----- fields (RollNo,Sub1,Sub2,Sub3)



if write join or inner query in sqlie> prompt it is work

select s.StudentName,m.sub1,m.sub2,m.sub3 from Student s,Marks m where s.RollNo = m.RollNo;


-------------------------------------------------------------------------------------------

but when i write it in to application it is not working



Cursor c = mydb.rawQuery("SELECT s.StudentName,m.sub1,m.sub2,m.sub3 FROM Student s,Marks m WHERE s.RollNo = m.RollNo LIMIT 7;", null);

int namecolumn = c.getColumnIndex("StudentName");
int rollnocolumn = c.getColumnIndex("RollNo");

if (c != null) {

if (c.moveToFirst()) {
int i = 0;
do {
i++;
int Sub1m = c.getInt(rollnocolumn);
int Sub2m = c.getInt(sub2column);
int Sub3m = c.getInt(sub3column);
String Name = c.getString(namecolumn);
// String stucolumName = c.getColumnName(namecolumn);

results.add("" + i + ":" + Name + ":" + Sub1m + ":" + sub2m + ":" + sub3m);

} while (c.moveToNext());
}
}

plz help how it done?
dhaiwat
Developer
Developer
 
Posts: 28
Joined: Tue Feb 10, 2009 6:49 am

Postby nuggetgtr » Wed Feb 25, 2009 3:34 am

Hi All,

hope someone can help me. I have a program which loads a spinner with a preset lot of values and then I will have people adding extra items which I will store in a database. but for now just testing it I am manully putting in some data. Im new to sql so im not quiet sure what im doing :D

here is my function

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. private void populatespinner(){
  2.  
  3.                 ArrayAdapter<String> saa=new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, spentonitems);
  4.  
  5.                 saa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  6.  
  7.                 spentonspin.setAdapter(saa);
  8.  
  9.                
  10.  
  11.         SQLiteDatabase mydb = null;
  12.  
  13.                 try {
  14.  
  15.         mydb = this.openOrCreateDatabase(MY_DATABASE_NAME, MODE_PRIVATE, null);
  16.  
  17.                 mydb.execSQL("CREATE TABLE IF NOT EXISTS "+ MY_DATABASE_TABLE + "(spent VARCHAR, num INT(2));");
  18.  
  19.                 mydb.execSQL("INSERT INTO " + MY_DATABASE_TABLE + " (spent, num)" + " VALUES ('TESTING', 2);)");
  20.  
  21.  
  22.  
  23.                 Cursor c = mydb.rawQuery("SELECT spent,num" + " FROM " + MY_DATABASE_TABLE + " WHERE num > 1;", null);
  24.  
  25.                
  26.  
  27.                 int spentcol = c.getColumnIndex("spent");
  28.  
  29.                 int numcol = c.getColumnIndex("num");
  30.  
  31.                 String spentonvar;
  32.  
  33.                 if (c != null) {
  34.  
  35.                         if (c.moveToFirst()) {
  36.  
  37.                                 int i = 0;
  38.  
  39.  
  40.  
  41.                                 do {
  42.  
  43.                                         i++;
  44.  
  45.                                         spentonvar = c.getString(spentcol);
  46.  
  47.                                         saa.add(spentonvar);
  48.  
  49.                                 } while (c.moveToNext());
  50.  
  51.                         }
  52.  
  53.                 }
  54.  
  55.       }  finally {
  56.  
  57.           if (mydb != null)
  58.  
  59.               mydb.close(); }
  60.  
  61.  
  62.  
  63. }
  64.  
  65.  
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


Im getting application stopped unexpectedly If I comment the DB stuff out and just have the first arrayadaper part, the program works fine with the set values.

hope someone can shead some light on this for me..

Cheers
nuggetgtr
Freshman
Freshman
 
Posts: 5
Joined: Tue Jan 06, 2009 3:14 am

Postby Klian » Wed Feb 25, 2009 12:11 pm

Hi :)

I have a problem with this simple testing code.

The problem with:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. this.createDatabase(MY_DATABASE_NAME, 1, MODE_PRIVATE, null);
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


It says:
"the method createDatabase is undefined"

Im noob at java...so any help would be appreciated :)

The code:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package org.klian.android.Hello_World;
  2.  
  3.  
  4.  
  5. import java.io.FileNotFoundException;
  6.  
  7. import java.util.ArrayList;
  8.  
  9.  
  10.  
  11. import android.app.ListActivity;
  12.  
  13. import android.database.Cursor;
  14.  
  15. import android.database.sqlite.SQLiteDatabase;
  16.  
  17. import android.os.Bundle;
  18.  
  19. import android.widget.ArrayAdapter;
  20.  
  21. import android.widget.EditText;
  22.  
  23. import android.util.Log;
  24.  
  25.  
  26.  
  27. public class Hello_World extends ListActivity {
  28.  
  29.         private final String MY_DATABASE_NAME = "LoginDB";
  30.  
  31.     private final String MY_DATABASE_TABLE = "Login1";
  32.  
  33.     private final String tag="Klian";
  34.  
  35.    
  36.  
  37.     public void onCreate(Bundle icicle) {
  38.  
  39.         super.onCreate(icicle);
  40.  
  41.        
  42.  
  43.         ArrayList<String> results = new ArrayList<String>();
  44.  
  45.         SQLiteDatabase myDB = null;
  46.  
  47.        
  48.  
  49.         try{
  50.  
  51.                
  52.  
  53.                 this.createDatabase(MY_DATABASE_NAME, 1, MODE_PRIVATE, null);
  54.  
  55.                 Log.i(tag,"Base de datos creada");
  56.  
  57.                
  58.  
  59.         }catch(Exception e){
  60.  
  61.                 Log.i(tag,"------"+e.getMessage());
  62.  
  63.             Log.i(tag,"++++++"+e);
  64.  
  65.         }
  66.  
  67.     }
  68.  
  69. }
Parsed in 0.039 seconds, using GeSHi 1.0.8.4
Klian
Freshman
Freshman
 
Posts: 4
Joined: Wed Feb 18, 2009 8:30 pm

Postby nuggetgtr » Wed Feb 25, 2009 11:28 pm

Kilan try
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. this.openOrCreateDatabase(MY_DATABASE_NAME, MODE_PRIVATE, null);
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


Think I had the same issue when using
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  this.createDatabase(MY_DATABASE_NAME, 1, MODE_PRIVATE, null);
Parsed in 0.035 seconds, using GeSHi 1.0.8.4
nuggetgtr
Freshman
Freshman
 
Posts: 5
Joined: Tue Jan 06, 2009 3:14 am

Postby pippo » Wed Mar 04, 2009 1:04 pm

hi @ all,

first of all sorry for my english..and thanks for posting tutorials like this.

i tried it but when i run the application all i get is a black screen. could anyone help me please (should i post my code for that?)
thanks in advance,

greets,
pippo
pippo
Freshman
Freshman
 
Posts: 3
Joined: Wed Mar 04, 2009 9:51 am

Top

Postby pippo » Fri Mar 06, 2009 9:00 pm

hey,

i solved my problem. but i have another question: how can i clear the result list?
thx to all,

greets
pippo
pippo
Freshman
Freshman
 
Posts: 3
Joined: Wed Mar 04, 2009 9:51 am

DB error...

Postby [XJrE] » Sun Mar 08, 2009 4:49 am

Hi people, i have a problem with my DB.

I have this code:
DB.java
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. package com.android.database;
  3.  
  4.  
  5.  
  6. import java.sql.SQLException;
  7.  
  8. import java.util.ArrayList;
  9.  
  10. import java.util.Map;
  11.  
  12.  
  13.  
  14. import android.app.ListActivity;
  15.  
  16.  
  17.  
  18. import android.database.sqlite.SQLiteDatabase;
  19.  
  20. import android.database.sqlite.SQLiteQueryBuilder;
  21.  
  22. import android.os.Bundle;
  23.  
  24.  
  25.  
  26.  
  27.  
  28. import android.app.Activity;
  29.  
  30. import android.content.ContentValues;
  31.  
  32. import android.content.Context;
  33.  
  34. import android.content.Intent;
  35.  
  36. import android.database.Cursor;
  37.  
  38. import java.io.FileNotFoundException;
  39.  
  40.  
  41.  
  42. import com.android.Parametros;
  43.  
  44. import com.android.WsMetodos;
  45.  
  46. import com.android.WsServicos;
  47.  
  48.  
  49.  
  50. import android.util.Log;
  51.  
  52. import android.view.View;
  53.  
  54. import android.view.View.OnClickListener;
  55.  
  56. import android.widget.Button;
  57.  
  58. import android.widget.EditText;
  59.  
  60.  
  61.  
  62.  
  63.  
  64. public class DB extends Activity{
  65.  
  66.        
  67.  
  68.         private Context dbContext;
  69.  
  70.         private static final String DATABASE_NAME = "DViewDB";
  71.  
  72.         private static final int DATABASE_VERSION = 1;
  73.  
  74.     private SQLiteDatabase dbDView;
  75.  
  76.         private WsServicos auxServico = new WsServicos();
  77.  
  78.         private WsMetodos auxMetodos = new WsMetodos();
  79.  
  80.         private Parametros auxParametros = new Parametros();
  81.  
  82.         private Parametros auxReturns = new Parametros();
  83.  
  84.        
  85.  
  86.         /**
  87.  
  88.     * Comandos SQL para criação das tabelas
  89.  
  90.     */
  91.  
  92.         private static final String TABLE_SERVICES =
  93.  
  94.                 "CREATE TABLE IF NOT EXISTS tbSERVICES " +
  95.  
  96.                 "(ID_SERVICE integer primary key autoincrement, " +
  97.  
  98.                 "NAME text not null, " +
  99.  
  100.                 "LOCATION text not null);";
  101.  
  102.        
  103.  
  104.         private static final String TABLE_METHODS =
  105.  
  106.                 "CREATE TABLE IF NOT EXISTS tbMETHODS " +
  107.  
  108.                 "(ID_METHOD integer primary key autoincrement, " +
  109.  
  110.                 "ID_SERVICE integer not null, " +
  111.  
  112.                 "NAME text not null, " +
  113.  
  114.                 "DESCRIPTION text not null);";
  115.  
  116.        
  117.  
  118.         private static final String TABLE_PARAMS =
  119.  
  120.                 "CREATE TABLE IF NOT EXISTS tbPARAMETERS " +
  121.  
  122.                 "(ID_PARAMETER integer primary key autoincrement, " +
  123.  
  124.                 "ID_METHOD integer not null, " +
  125.  
  126.                 "NAME text not null, " +
  127.  
  128.                 "TYPE text not null);";
  129.  
  130.        
  131.  
  132.         private static final String TABLE_RETURNS =
  133.  
  134.                 "CREATE TABLE IF NOT EXISTS tbRETURNS " +
  135.  
  136.                 "(ID_RETURN integer primary key autoincrement, " +
  137.  
  138.                 "ID_METHOD integer not null, " +
  139.  
  140.                 "NAME text not null, " +
  141.  
  142.                 "TYPE text not null);";
  143.  
  144.        
  145.  
  146.     public DB(Context context) {
  147.  
  148.         this.dbContext = context;
  149.  
  150.        
  151.  
  152.         dbDView = dbContext.openOrCreateDatabase(DATABASE_NAME, MODE_PRIVATE, null);
  153.  
  154.        
  155.  
  156.         dbDView.execSQL(TABLE_SERVICES);
  157.  
  158.         dbDView.execSQL(TABLE_METHODS);
  159.  
  160.         dbDView.execSQL(TABLE_PARAMS);
  161.  
  162.         dbDView.execSQL(TABLE_RETURNS);
  163.  
  164.     }
  165.  
  166.    
  167.  
  168.     public void closeDB(){
  169.  
  170.         dbDView.close();
  171.  
  172.     }
  173.  
  174.    
  175.  
  176.     /**
  177.  
  178.      * Create a new note using the title and body provided. If the note is successfully created
  179.  
  180.      * return the new rowId for that note, otherwise return a -1 to indicate failure.
  181.  
  182.      * @param title the title of the note
  183.  
  184.      * @param body the body of the note
  185.  
  186.      * @return rowId or -1 if failed
  187.  
  188.      */
  189.  
  190.  
  191.  
  192.         public long createElement(String dbTable, ContentValues values) {
  193.  
  194.                 return dbDView.insert(dbTable, null, values);
  195.  
  196.         }
  197.  
  198.        
  199.  
  200.     /**
  201.  
  202.      * Update the note using the details provided. The note to be updated is specified using
  203.  
  204.      * the rowId, and it is altered to use the title and body values passed in
  205.  
  206.      * @param rowId id of note to update
  207.  
  208.      * @param title value to set note title to
  209.  
  210.      * @param body value to set note body to
  211.  
  212.      * @return true if the note was successfully updated, false otherwise
  213.  
  214.      */
  215.  
  216.     public boolean updateElement(String dbTable, ContentValues values, String selection) {
  217.  
  218.         return dbDView.update(dbTable, values, selection, null) > 0;
  219.  
  220.     }
  221.  
  222.    
  223.  
  224.     /**
  225.  
  226.      * Return a Cursor over the list of all elements in the database
  227.  
  228.      * @return Cursor over all elements
  229.  
  230.      */
  231.  
  232.         public Cursor fetchAllElements(String dbTable, String[] column) {
  233.  
  234.         return dbDView.query(dbTable, column, null, null, null, null, null);
  235.  
  236.     }
  237.  
  238.  
  239.  
  240.     /**
  241.  
  242.      * Return a Cursor positioned at the element that matches the given selection
  243.  
  244.      * @param
  245.  
  246.      * @return Cursor positioned to matching element, if found
  247.  
  248.      * @throws SQLException if element could not be found/retrieved
  249.  
  250.      */
  251.  
  252.     //public Cursor fetchElementSQL(String dbTable, String[] column, String selection, String[] selectionArgs) {
  253.  
  254.    
  255.  
  256.         public Cursor fetchElementSQL(String sql) {
  257.  
  258.         return dbDView.rawQuery(sql, null);
  259.  
  260.     }
  261.  
  262.        
  263.  
  264.     /**
  265.  
  266.      * Return a Cursor positioned at the element that matches the given selection
  267.  
  268.      * @param
  269.  
  270.      * @return Cursor positioned to matching element, if found
  271.  
  272.      * @throws SQLException if element could not be found/retrieved
  273.  
  274.      */
  275.  
  276.     public Cursor fetchElement(String dbTable, String[] column, String selection, String[] selectionArgs) {
  277.  
  278.        
  279.  
  280.         SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
  281.  
  282.         qb.setTables(dbTable);
  283.  
  284.         qb.appendWhere(selection);
  285.  
  286.        
  287.  
  288.         Cursor c = qb.query(dbDView, null, null, selectionArgs, null, null, null);
  289.  
  290.         return c;
  291.  
  292.         /*
  293.  
  294.         Cursor result = mDb.query(dbTable, column, selection, selectionArgs, null, null, null);
  295.  
  296.         if ((result.getCount() == 0) || !result.isFirst()) {
  297.  
  298.             throw new SQLException("No element matching ID: " + column);
  299.  
  300.         }
  301.  
  302.         return result;
  303.  
  304.         */
  305.  
  306.     }
  307.  
  308.    
  309.  
  310.     public Boolean saveServices(Map services){
  311.  
  312.        
  313.  
  314.         ContentValues values = new ContentValues();
  315.  
  316.         int qntd = 0;
  317.  
  318.         long rowID = 0;
  319.  
  320.        
  321.  
  322.         try {
  323.  
  324.                 for (int q = 0; q<=services.size(); q++){
  325.  
  326.                         auxServico = (WsServicos) services.get(q);
  327.  
  328.                         values.put("NAME", auxServico.getNome());
  329.  
  330.                         values.put("LOCATION", auxServico.getAddressLocation());
  331.  
  332.                        
  333.  
  334.                         rowID = this.createElement(TABLE_SERVICES, values);
  335.  
  336.                 }
  337.  
  338.                 } catch (Exception e) {
  339.  
  340.                         // TODO: handle exception
  341.  
  342.                         return false;
  343.  
  344.                 }
  345.  
  346.                 return false;
  347.  
  348.     }
  349.  
  350. }
  351.  
  352.  
Parsed in 0.055 seconds, using GeSHi 1.0.8.4


...and log error is:
Code: Select all
03-08 01:31:03.096: WARN/dalvikvm(450): threadid=3: thread exiting with uncaught exception (group=0x40010e28)
03-08 01:31:03.104: ERROR/AndroidRuntime(450): Uncaught handler: thread main exiting due to uncaught exception
03-08 01:31:03.295: ERROR/AndroidRuntime(450): java.lang.NullPointerException
03-08 01:31:03.295: ERROR/AndroidRuntime(450):     at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:181)
03-08 01:31:03.295: ERROR/AndroidRuntime(450):     at com.android.database.DB.openOrCreateDB(DB.java:77)
03-08 01:31:03.295: ERROR/AndroidRuntime(450):     at com.android.SearchServices.<init>(SearchServices.java:22)
03-08 01:31:03.295: ERROR/AndroidRuntime(450):     at com.android.DView$3.onClick(DView.java:80)
03-08 01:31:03.295: ERROR/AndroidRuntime(450):     at android.view.View.performClick(View.java:2109)
03-08 01:31:03.295: ERROR/AndroidRuntime(450):     at android.view.View.onTouchEvent(View.java:3523)
03-08 01:31:03.295: ERROR/AndroidRuntime(450):     at android.widget.TextView.onTouchEvent(TextView.java:4410)
03-08 01:31:03.295: ERROR/AndroidRuntime(450):     at android.view.View.dispatchTouchEvent(View.java:3178)
03-08 01:31:03.295: ERROR/AndroidRuntime(450):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:857)
03-08 01:31:03.295: ERROR/AndroidRuntime(450):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:857)
03-08 01:31:03.295: ERROR/AndroidRuntime(450):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:857)
03-08 01:31:03.295: ERROR/AndroidRuntime(450):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:857)
03-08 01:31:03.295: ERROR/AndroidRuntime(450):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1561)
03-08 01:31:03.295: ERROR/AndroidRuntime(450):     at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1085)
03-08 01:31:03.295: ERROR/AndroidRuntime(450):     at android.app.Activity.dispatchTouchEvent(Activity.java:1873)
03-08 01:31:03.295: ERROR/AndroidRuntime(450):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1545)
03-08 01:31:03.295: ERROR/AndroidRuntime(450):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1140)
03-08 01:31:03.295: ERROR/AndroidRuntime(450):     at android.os.Handler.dispatchMessage(Handler.java:88)
03-08 01:31:03.295: ERROR/AndroidRuntime(450):     at android.os.Looper.loop(Looper.java:123)
03-08 01:31:03.295: ERROR/AndroidRuntime(450):     at android.app.ActivityThread.main(ActivityThread.java:3742)
03-08 01:31:03.295: ERROR/AndroidRuntime(450):     at java.lang.reflect.Method.invokeNative(Native Method)
03-08 01:31:03.295: ERROR/AndroidRuntime(450):     at java.lang.reflect.Method.invoke(Method.java:515)
03-08 01:31:03.295: ERROR/AndroidRuntime(450):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
03-08 01:31:03.295: ERROR/AndroidRuntime(450):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:497)
03-08 01:31:03.295: ERROR/AndroidRuntime(450):     at dalvik.system.NativeStart.main(Native Method)


Can help me?

Sorry for my bad english.

Jr.
[XJrE]
Freshman
Freshman
 
Posts: 2
Joined: Sun Mar 08, 2009 3:35 am

Postby isaackearl » Mon Mar 09, 2009 1:22 am

Hey,

I got really excited when I found this tutorial. I've worked with databases before, but am having trouble getting one going in android. I downloaded the source you have here and I couldn't get it working. none of the layouts etc and resources you refer to are there.. and I think the tutorial is to old for the current build of android. I could really use some help on this, so if you could update this tutorial that would be fantastic.

thanks,
Isaac
isaackearl
Junior Developer
Junior Developer
 
Posts: 20
Joined: Tue Nov 25, 2008 8:09 pm

Re: Plz help

Postby desuvinodkumar » Tue Mar 24, 2009 8:13 am

cybersat wrote:hi,
Please attach full working source code, i am unable to view database details.
1. Kindly attach full source code.zip
2. How can we view databases and tables using command prompt.






i'm getting the error while i'm running the databasework project
ERROR org.anddev.android.databasework.DataBaseWork does not extend android.app.Activity

Code iS
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.anddev.android.databasework">
<application android:icon="@drawable/icon"
android:label="@string/app_name">
<activity android:name=".DataBaseWork"
android:label="@string/app_name">

<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

Can i know where is the Problem
Vinod...
User avatar
desuvinodkumar
Senior Developer
Senior Developer
 
Posts: 102
Joined: Mon Mar 23, 2009 6:51 am
Location: India

Saving

Postby cjules86 » Wed Apr 15, 2009 8:53 pm

Hi,

Can anyone tell me if the sqlite DB is automatically saved (i.e. you close the application and then load it and work with the database again)? Currently I have a working sqlite db but when i close the application (this.finish()) and then start the app up again it does not load data.

Example:
1) I insert a value of 3 into a table, then do a query to retrieve information from that table and it returns 3.
2) I insert a value of 3 into a table, then quit the application with this.finish(), then start the application again and do the same query and it returns a value of 0.

Am I closing the application incorrectly? Any help is appreciated.

Here is basically what I do in my "loadDB" function:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. myDB = a.openOrCreateDatabase("gstock_user_data", MODE_PRIVATE, null);
  3.  
  4.                        
  5.  
  6.                         //Get money info
  7.  
  8.                         Cursor c = myDB.query("Money", new String[] {"banktransactions", "bankaccount"}, null, null, null, null, null);
  9.  
  10.                         if(c != null)
  11.  
  12.                         {
  13.  
  14.                                 if(c.getCount() == 1)
  15.  
  16.                                 {
  17.  
  18.                                         banktransactions = Integer.parseInt(c.getString(c.getColumnIndex("banktransactions")));
  19.  
  20.                                         bankaccount = Integer.parseInt(c.getString(c.getColumnIndex("bankaccount")));
  21.  
  22.                                 }
  23.  
  24.                         }
  25.  
  26.                         return banktransactions;
  27.  
  28.  
Parsed in 0.037 seconds, using GeSHi 1.0.8.4
cjules86
Freshman
Freshman
 
Posts: 5
Joined: Wed Apr 15, 2009 8:42 pm

Postby ddtdpro » Thu Jun 25, 2009 4:22 am

pippo wrote:hi @ all,

first of all sorry for my english..and thanks for posting tutorials like this.

i tried it but when i run the application all i get is a black screen. could anyone help me please (should i post my code for that?)
thanks in advance,

greets,
pippo


i also have the same problem with you. I run and i have a blank screen. I did change something is the code, some functions don't exist like (myDB.createDatabase, c.first(), c.next() ) so i change to (myDB.openOrCreateDatabase, c.isFirst(), c.moveToNext() ). Is it correct or did i change anything wrong? can you help me plz? I have to do something with the database but i can't find any other good examples but this

Thanks
User avatar
ddtdpro
Freshman
Freshman
 
Posts: 6
Joined: Sat May 02, 2009 5:39 pm

Postby CoCo » Wed Jul 15, 2009 10:25 pm

Hey PlusMimus,

Thank you so much for showing how to create a SQLite database. I am new Android user and I am currently working on my first Android game. Now I am trying to figure out how to create a high score table that would display the top 10 scores and store data in the SQLite database( instead of using a service like many game developers do). I read many tutorials on high score lists and SqLite database but they were not very helpful. Can you please help with this issue.

Thanks kindly
CoCo
Freshman
Freshman
 
Posts: 2
Joined: Wed Jul 15, 2009 10:15 pm

Postby nmc » Thu Jul 16, 2009 1:44 am

Now I am trying to figure out how to create a high score table that would display the top 10 scores and store data in the SQLite database

Create:
create table hi (player: text, score: integer)


Display:
select player, score
from hi
order by score desc
limit 10
nmc
Senior Developer
Senior Developer
 
Posts: 154
Joined: Thu Nov 27, 2008 8:30 pm
Location: Germany

Postby Rashi » Fri Sep 11, 2009 3:05 pm

I am having some errors when i run this code which are:

1.openDatabase(MY_DATABASE_NAME, null);
2.createDatabase(MY_DATABASE_NAME, 1, MODE_PRIVATE, null);

It says to create these gunctions and then use it.

Rashi.
Rashi
Developer
Developer
 
Posts: 32
Joined: Thu Sep 10, 2009 11:28 am

Top
PreviousNext

Return to Novice Tutorials

Who is online

Users browsing this forum: No registered users and 4 guests