Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8371745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:14:14+00:00 2026-06-09T14:14:14+00:00

I’m implementing an Android Application now. I made a database in the application, and

  • 0

I’m implementing an Android Application now.
I made a database in the application, and I tried to check it DDMS and SQLite Database Browser 2.0 b1.

The table I created has several rows (I could checked by System.out.println in my program), but only the 1st row is showed in SQLite Database Browser.

The latest updated time of database file which is showed in DDMS is correct.

Please let me know how I can resolve this problem.

public void onCreate(Bundle savedInstanceState) {

        StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
                .permitAll().build());

        super.onCreate(savedInstanceState);
        setContentView(R.layout.twitterdata);

        helper = new CreateTableHelper(TwitterData.this);

        db = helper.getWritableDatabase();

        mSharedPreferences = getSharedPreferences(Const.PREFERENCE_NAME,
                MODE_PRIVATE);
        /**
         * Handle OAuth Callback
         */
        Uri uri = getIntent().getData();
        if (uri != null && uri.toString().startsWith(Const.CALLBACK_URL)) {
            String verifier = uri
                    .getQueryParameter(Const.IEXTRA_OAUTH_VERIFIER);
            try {
                AccessToken accessToken = twitter.getOAuthAccessToken(
                        requestToken, verifier);

                User user = twitter.verifyCredentials();

                List<Status> statuses = twitter.getUserTimeline(user
                        .getScreenName());

                for (Status status : statuses) {
                    String tweet = status.getText();
                    String[] words = tweet.split(" ");

                    for (int i = 0; i < words.length; i++) {
                        if (words[i].length() > 1) {
                            String requestURL = "http://en.wikipedia.org/w/api.php?action=query&prop=categories&format=json&clshow=!hidden&cllimit=10&titles="
                                    + words[i];

                            URL wikiRequest = new URL(requestURL);
                            URLConnection connection = wikiRequest
                                    .openConnection();
                            connection.setDoOutput(true);

                            Scanner scanner = new Scanner(
                                    wikiRequest.openStream());
                            String response = scanner.useDelimiter("\\Z")
                                    .next();
                            JSONObject json = Util.parseJson(response);
                            JSONObject query = json.getJSONObject("query");
                            JSONObject pages_jsn = query.getJSONObject("pages");
                            String pages = query.getString("pages");

                            int dqm_cnt = 0;
                            int dqm_while = 0;
                            String page_id_str = "";
                            Character dq = pages.charAt(0);
                            while (dqm_cnt < 2) {
                                Character tmp = pages.charAt(dqm_while);
                                if (tmp.equals(dq)) {
                                    dqm_cnt++;
                                }
                                try {
                                    Integer.parseInt(tmp.toString());
                                    page_id_str += tmp;
                                } catch (NumberFormatException e) {
                                }
                                dqm_while++;
                            }

                            int page_id = Integer.parseInt(page_id_str);

                            // The article is available.
                            if (page_id != 1) {
                                JSONObject pageidjson = pages_jsn
                                        .getJSONObject(page_id_str);
                                db.beginTransaction();
                                try {
                                    // category is available
                                    String tmp_interest = pageidjson
                                            .getString("title");
                                    JSONArray categories_array = pageidjson
                                            .getJSONArray("categories");

                                    // interests
                                    db = helper.getReadableDatabase();
                                    String[] i_columns = { "id", "name",
                                            "count" };
                                    SQLiteCursor ic = (SQLiteCursor) db.query(
                                            "interests", i_columns, "name = '"
                                                    + tmp_interest + "'", null,
                                            null, null, null);
                                    db.setTransactionSuccessful();
                                    db.endTransaction();

                                    if (ic.getCount() == 0) {
                                        db = helper.getWritableDatabase();
                                        db.beginTransaction();

                                        ContentValues val_interest = new ContentValues();
                                        val_interest.put("name", tmp_interest);
                                        val_interest.put("count", 1);
                                        db.insert("interests", null,
                                                val_interest);
                                        System.out.println("successfully inserted " + tmp_interest);
                                        db.setTransactionSuccessful();
                                        db.endTransaction();
                                    } else {
                                        ic.moveToFirst();
                                        int i_id = ic.getInt(0);
                                        db.beginTransaction();
                                        ContentValues db_i_val = new ContentValues();
                                        db_i_val.put("count", ic.getInt(2) + 1);
                                        db.update("interests", db_i_val, "id = "
                                                + i_id, null);
                                        db.setTransactionSuccessful();
                                        db.endTransaction();

                                    }

                                } catch (Exception e) {
                                    Log.e("ERROR", e.toString());
                                }
                            }

                            scanner.close();

                        }

                    }

                    System.out.println("@" + status.getUser().getScreenName()
                            + " - " + status.getText());
                }
                db = helper.getReadableDatabase();
                String[] i_columns = { "id", "name",
                        "count" };
                SQLiteCursor test = (SQLiteCursor) db.query(
                        "interests", i_columns, null, null,
                        null, null, null);
                System.out.println("Table Interests has " + test.getColumnCount() + "rows");

                db.setTransactionSuccessful();
                db.endTransaction();

                db.close();

                Editor e = mSharedPreferences.edit();
                e.putString(Const.PREF_KEY_TOKEN, accessToken.getToken());
                e.putString(Const.PREF_KEY_SECRET, accessToken.getTokenSecret());
                e.commit();
            } catch (Exception e) {
                Log.e(TAG, e.getMessage());
            }
        }

    }

Solve

  • Use System.out.println("Table Interests has " + test.getCount() + "rows"); instead of System.out.println("Table Interests has " + test.getColumnCount() + "rows");

Then I can get a correct number of rows.

  • I should to be careful the position of db.beginTransaction(). Im my cord, there is try between db.beginTransaction() and db.endTransaction(). That did not work correctly.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T14:14:15+00:00Added an answer on June 9, 2026 at 2:14 pm

    This is incorrect:

    System.out.println("Table Interests has " + test.getColumnCount() + "rows");
    

    This will print the number of columns.

    You should be using:

    System.out.println("Table Interests has " + test.getCount() + "rows");
    

    Documentation
    http://developer.android.com/reference/android/database/sqlite/SQLiteCursor.html#getCount()

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.