Parvathi Krishnan
Parvathi Krishnan

Reputation: 73

How to update the tables in dataclass IBM?

I am trying to update a dataclass table with extra values after inserting some fields in the columns,again if i want insert the details in the same column,its not working,it gets in the second row,could anyone please help me,i want this answer as soon as possible

Upvotes: 0

Views: 93

Answers (2)

Jeff Sloyer
Jeff Sloyer

Reputation: 4964

    // Find a set of objects by class
    IBMQuery<Item> queryByClass = IBMQuery.queryForClass(Item.class);

    // Find a specific object
    IBMQuery<Item> queryForObject = myItem.getQuery();

    query.find().continueWith(new Continuation<List<Item>, Void>() {

        @Override
        public Void then(Task<List<Item>> task) throws Exception {
            if (task.isFaulted()) {
                // Handle errors
            } else {
                // do more work
                List<Item> objects = task.getResult();
            }
            return null;
        }
    });

This code came from http://mbaas-gettingstarted.ng.bluemix.net/android

Upvotes: 0

Parvathi Krishnan
Parvathi Krishnan

Reputation: 73

This is how I updated the row in bluemix by getting a particular column value position. Here is the code.

This is the code for getting the entire values from the bluemix table:

IBMQuery<Company> query = IBMQuery.queryForClass(Company.CLASS_NAME);
        query.find().continueWith(new Continuation<List<Company>, Void>() {

            public Void then(Task<List<Company>> task) throws Exception {
                final List<Company> objects = task.getResult();
                // Log if the find was cancelled.
                if (task.isCancelled()) {
                    Log.e(CLASS_NAME, "Exception : Task " + task.toString()
                            + " was cancelled.");
                }
                // Log error message, if the find task fails.
                else if (task.isFaulted()) {
                    Log.e(CLASS_NAME, "Exception : "
                            + task.getError().getMessage());
                }

                // If the result succeeds, load the list.
                else {
                    companyList.clear();
                    for (IBMDataObject storeObject : objects) {
                        companyList.add((Company) storeObject);
                    }
                    if (task.isCompleted()) {
                        handler.sendEmptyMessage(2);

                    }

                }

Where Company is the name of the Table and companyList is the company class array list.

After this code is executed the companylist will get all the rows and columns values stored in bluemix from which we can get the required row by using the query

query.whereKeyEqualsTo(User.RegisterName, userName);
query.whereKeyEqualsTo(User.Password, password);

Where User is the table name RegisterName and Password are static variable defined in the User Class userName and password is the user defined given inputs. By getting the position of the required row retrieved in companyList, I do the update in the following way:

Company companyObject=Company.getPosition(position);
companyObject.setName("Something");
companyObject.save() query......

Now the problem is I'm able to do the update properly, but I'm not able to retrieve the table values from bluemix using the code which I mentioned in the top.

Upvotes: 1

Related Questions