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 9145979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:38:50+00:00 2026-06-17T10:38:50+00:00

After creating the table with pm.createTable() and adding data to it using pm.addDataToTable() ,

  • 0

After creating the table with pm.createTable() and adding data to it using pm.addDataToTable(), I am trying to retrieve the data using pm.getData() of the same table, that i just created and inserted, and store it in cursor c. I am not getting any compilation errors or exceptions. The control always enters the else condition in displayData(). Can someone help me with this?

PortfolioManager pm;
Cursor c, cMainTable; 

pm = new PortfolioManager(this);        
cMainTable = pm.getData("mainTable");

scriptName = edtxtScriptName.getText().toString();


   try
                {
                System.out.println("Creating table with name "+scriptName);
                pm.createTable(scriptName);
                System.out.println("Table created");
                pm.addDataToTable(scriptName, DOP, purchasedQuantity, purchasedPrice, brokerage, serviceTax, stt, stampDuty);
                System.out.println("data added");

                c = pm.getData(scriptName);
                displayData(c);
                }
                catch (Exception e) {
                    // TODO: handle exception
                    System.out.println("Exception at try catch block");
                }

    private void displayData(Cursor c2) {
            // TODO Auto-generated method stub

            if(c2 != null) // Should enter this statement. Always enters else condition
            {                   
                if(c2.getCount() > 0)
                {
                    c2.moveToFirst();

                    do
                    {

                        // obtain data from cursor

                    }while(c2.moveToNext());
                }
            }
            else
            {
                System.out.println("Cursor c2 is Empty");
            }

        }

portfoliomanager.java

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

public class PortfolioManager extends SQLiteOpenHelper{

    static String name = "portfolio";
    static int version = 1;

    SQLiteDatabase sqlDB;
    Cursor c;

    public PortfolioManager(Context context) {
        super(context, name, null, version);
        // TODO Auto-generated constructor stub

        sqlDB = getWritableDatabase();

    }
    @Override
    public void onCreate(SQLiteDatabase sqlDB) {
        // TODO Auto-generated method stub

        sqlDB.execSQL("create table if not exists maintable(scriptnumber text, scriptname text, totalquantity int, " +
                "averageprice double, lossorgain double)");

    }
    @Override
    public void onUpgrade(SQLiteDatabase sqlDB, int oldVersion, int newVersion) {
        // TODO Auto-generated method stub

    }
    public Cursor getData(String string) {
        // TODO Auto-generated method stub

        String table = string;

        sqlDB.rawQuery("select * from "+table, null);       
        return c;
    }
    public void addDataToTable(String scriptName, String dOP, int purchasedQuantity, double purchasedPrice, 
            double brokerage, double serviceTax, double stt, double stampDuty) {
        // TODO Auto-generated method stub


        sqlDB.execSQL("insert into "+scriptName+" values('"+dOP+"', '"+purchasedQuantity+"', '"+purchasedPrice+"'," +
                "'"+brokerage+"', '"+serviceTax+"', '"+stt+"', '"+stampDuty+"')");
    }
    public void createTable(String scriptName) {
        // TODO Auto-generated method stub

        sqlDB.execSQL("create table if not exists "+scriptName+"(dateofpurchase text, purchasedquantity int, purchasedprice double," +
                " brokerage double, servicetax double, stt double, stampduty double)");

    }



}

Output :::

01-17 23:38:16.799: I/System.out(23248): Creating table with name nal
01-17 23:38:16.869: I/System.out(23248): Table created
01-17 23:38:16.929: I/System.out(23248): data added
01-17 23:38:16.929: I/System.out(23248): Cursor c2 is Empty
  • 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-17T10:38:51+00:00Added an answer on June 17, 2026 at 10:38 am

    You are not Assign value of cursor in this method getData(String string);

    I think your getData(String string) method should be like this instead of old one:

    public Cursor getData(String string) {
            // TODO Auto-generated method stub
            Curser c= null;
            String table = string;
    
           c = sqlDB.rawQuery("select * from "+table, null);   
    
            return c;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After creating table using exec() in PDO,it shows like this Array ( [0] =>
In the first time I have created one Table DEPTS . After that I
After creating a table (by migration), I want to insert some entries directly. How
After creating the parse tree, i have to populate symbol table now. I have
After creating a metaclass using Moose::Meta::Class->create , how do I instantiate a real Moose
After creating a listview from VS2010 and adding it as a web part to
I have an XML file containing seed data that I'm trying to load into
My scenario..Im using SqlCompactServer Edition .I'm creating table Create Table SSr( name nvarchar(400),id int
I've just converted MYISAM into InnoDB. Before doing that, I've saved the table (see
i am trying to create an order management system but after creating base tables

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.