Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: SQLite Android Question.

  1. #1
    Member
    Join Date
    Sep 2012
    Location
    Philippines
    Posts
    46
    My Mood
    Cheeky
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default SQLite Android Question.

    How do I fetch a single value from a row in SQLite? for example I have the method getLevel() and a row with "id, coin, level" and the getLevel() is used to get and return the levelonly. How can i do that? Here's my code.

    public int getLevel(int id) {
    		int level = 0;
            String selectQuery = "SELECT "+colCurrentLvl+" FROM " + userTable + " WHERE " +userID + "="+id; 
     
            SQLiteDatabase db = this.getReadableDatabase();
            Cursor cursor = db.rawQuery(selectQuery, null);
     
            if (null != cursor && cursor.moveToFirst()) {
                level = Integer.parseInt(cursor.getString(cursor.getColumnIndex(colCurrentLvl)));
            }
     
            cursor.close();
    	    db.close();
     
            return level;
    	}

    And in my Main Class i need to set it like this.

    int level = db.getLevel(1);

    but my emulator force closes. Any help?


  2. #2
    Member
    Join Date
    Sep 2012
    Location
    Philippines
    Posts
    46
    My Mood
    Cheeky
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: SQLite Android Question.

    Hello?

Similar Threads

  1. java cant find my sqlite file
    By xchan in forum JDBC & Databases
    Replies: 1
    Last Post: August 13th, 2013, 12:33 PM
  2. How to delete from SQLite
    By hno2005 in forum JDBC & Databases
    Replies: 1
    Last Post: November 29th, 2012, 10:17 AM
  3. [SOLVED] NetBeans and SQLite error
    By Boquito17 in forum JDBC & Databases
    Replies: 3
    Last Post: October 13th, 2012, 04:46 PM
  4. Help with sqlite please
    By mikesummer78 in forum JDBC & Databases
    Replies: 1
    Last Post: July 5th, 2012, 08:26 PM
  5. SQLite and Desktop Application
    By urosz in forum JDBC & Databases
    Replies: 12
    Last Post: November 2nd, 2009, 03:50 AM

Tags for this Thread