views:

20

answers:

1

hi;

I have been trying from last three days and i was not able to solve this problem;ed the tables and qurie

I have been using perstlite for storing the data; i have created tables and Queries for the requried class; Now i have been listening to contacts in the mobile and i am able to get the data in that class only but i am not able to get the information in the main class or any where in the project though i have called the class. can any buddy help me in this issue.

This is my program

package com.Wblower.listeners;

import java.util.Hashtable;

import javax.microedition.pim.Contact; import javax.microedition.pim.PIMItem; import javax.microedition.pim.PIMList; import com.Wblower.db.ContactlistdatabaseQueries; import com.Wblower.db.Contactlistdatabasetable; import com.Wblower.db.DataBaseConnectivity; import com.Wblower.util.DateTimeUtil;

import net.rim.blackberry.api.pdap.BlackBerryContact; import net.rim.blackberry.api.pdap.BlackBerryContactList; import net.rim.blackberry.api.pdap.PIMListListener;

public class ContactListener implements PIMListListener {

BlackBerryContactList contactList;
DataBaseConnectivity dbconnectVity = new DataBaseConnectivity();

public void itemAdded(PIMItem arg0) {

    System.out.println("Item Added ==");
    String firstname = "none";
    String lastname = "none";
    String mobile = "none";
    String mobile1 = "none";
    String mobile2 = "none";
    String email = "none";
    String email1 = "none";
    String web = "none";
    String company = "none";
    String address = "none";
    String address1 = "none";
    String name[] = { "" };
    String timeStamp = "none";

    PIMList contacts = arg0.getPIMList();
    Contact contact = (Contact) arg0;

    if (contacts.isSupportedField(Contact.NAME)) {

        try {
            if (contact.countValues(Contact.NAME) > 0)
                name = contact.getStringArray(Contact.NAME, 0);
            if (name[Contact.NAME_GIVEN] != null)
                firstname = name[Contact.NAME_GIVEN];
            System.out.println("FirstName= " + firstname);
            if (name[Contact.NAME_FAMILY] != null)
                lastname = name[Contact.NAME_FAMILY];
            System.out.println("LastName= " + lastname);
        } catch (Exception e) {
            System.out.println("Exception::" + e.getMessage());
        }

    }
    if (contacts.isSupportedField(Contact.EMAIL)) {
        try {
            if (contact.countValues(Contact.EMAIL) > 0)
                email = contact.getString(Contact.EMAIL, 0);
            System.out.println("Email " + email);

            if (contact.countValues(Contact.EMAIL) > 1)
                email1 = contact.getString(Contact.EMAIL, 1);
            System.out.println("Email " + email1);
        } catch (Exception e) {
            System.out.println("Exception::" + e.getMessage());
        }
    }

    if (contacts.isSupportedField(Contact.ORG)) {

        try {
            if (contact.countValues(Contact.ORG) > 0)
                company = contact.getString(Contact.ORG, 0);
            System.out.println("Company " + company);
        } catch (Exception e) {
            System.out.println("Exception::" + e.getMessage());
        }
    }

    if (contacts.isSupportedField(Contact.URL)) {
        try {
            if (contact.countValues(Contact.URL) > 0)
                web = contact.getString(Contact.URL, 0);
            System.out.println("web " + web);
        } catch (Exception e) {
            System.out.println("Exception::" + e.getMessage());
        }
    }
    if (contacts.isSupportedField(Contact.TEL)) {
        try {
            if (contact.countValues(Contact.TEL) > 0)
                mobile = contact.getString(Contact.TEL, 0);
            System.out.println("Phone " + mobile);

            if (contact.countValues(Contact.TEL) > 1)
                mobile1 = contact.getString(Contact.TEL, 1);
            System.out.println("Phone " + mobile1);

            if (contact.countValues(Contact.TEL) > 2)
                mobile2 = contact.getString(Contact.TEL, 2);
            System.out.println("Phone " + mobile2);
        } catch (Exception e) {
            System.out.println("Exception::" + e.getMessage());
        }
        if (contacts.isSupportedField(Contact.ADDR)) {

            try {
                address = "";
                String[] addressarr = contact.getStringArray(
                        BlackBerryContact.ADDR, 0);

                for (int i = 0; i < addressarr.length; i++) {

                    if (addressarr[i] != null) {
                        address = address + " " + addressarr[i];

                    }

                }
                System.out.println("Address==" + address);

                address1 = "";
                String[] addressar = contact.getStringArray(
                        BlackBerryContact.ADDR, 1);

                for (int i = 0; i < addressar.length; i++) {
                    if (addressar[i] != null) {
                        address1 = address1 + " " + addressar[i];

                    }

                }
                System.out.println("Address==" + address1);
            } catch (Exception e) {
                System.out.println("Exception::" + e.getMessage());
            }

            timeStamp = DateTimeUtil.timestamp();

            try {

                System.out.println("Entering into the db");
                dbconnectVity.setDataBase();
                Contactlistdatabasetable Contactlist;
                Contactlist = new Contactlistdatabasetable(
                        "Contacts", "Add", firstname, lastname, mobile,
                        mobile1, mobile2, email, email1, web, company,
                        address, address1, timeStamp);
                ContactlistdatabaseQueries.insertSingleContactlist(Contactlist);
                ContactlistdatabaseQueries.selectWholeContactlist();         
            } catch (Exception e) {
                System.out.println("Exception::" + e.getMessage());
            }

            return;

        }

    }

}

public void itemRemoved(PIMItem arg0) {
    System.out.println("Item Removed ==");
    String firstname = "none";
    String lastname = "none";
    String mobile = "none";
    String mobile1 = "none";
    String mobile2 = "none";
    String email = "none";
    String email1 = "none";
    String web = "none";
    String company = "none";
    String address = "none";
    String address1 = "none";
    String name[] = { "" };
    String timeStamp = "none";

    PIMList contacts = arg0.getPIMList();
    Contact contact = (Contact) arg0;

    if (contacts.isSupportedField(Contact.NAME)) {

        try {
            if (contact.countValues(Contact.NAME) > 0)
                name = contact.getStringArray(Contact.NAME, 0);
            if (name[Contact.NAME_GIVEN] != null)
                firstname = name[Contact.NAME_GIVEN];
            System.out.println("FirstName= " + firstname);
            if (name[Contact.NAME_FAMILY] != null)
                lastname = name[Contact.NAME_FAMILY];
            System.out.println("LastName= " + lastname);
        } catch (Exception e) {
            System.out.println("Exception::" + e.getMessage());
        }

    }
    if (contacts.isSupportedField(Contact.EMAIL)) {
        try {
            if (contact.countValues(Contact.EMAIL) > 0)
                email = contact.getString(Contact.EMAIL, 0);
            System.out.println("Email " + email);

            if (contact.countValues(Contact.EMAIL) > 1)
                email1 = contact.getString(Contact.EMAIL, 1);
            System.out.println("Email " + email1);
        } catch (Exception e) {
            System.out.println("Exception::" + e.getMessage());
        }
    }

    if (contacts.isSupportedField(Contact.ORG)) {

        try {
            if (contact.countValues(Contact.ORG) > 0)
                company = contact.getString(Contact.ORG, 0);
            System.out.println("Company " + company);
        } catch (Exception e) {
            System.out.println("Exception::" + e.getMessage());
        }
    }

    if (contacts.isSupportedField(Contact.URL)) {
        try {
            if (contact.countValues(Contact.URL) > 0)
                web = contact.getString(Contact.URL, 0);
            System.out.println("web " + web);
        } catch (Exception e) {
            System.out.println("Exception::" + e.getMessage());
        }
    }
    if (contacts.isSupportedField(Contact.TEL)) {
        try {
            if (contact.countValues(Contact.TEL) > 0)
                mobile = contact.getString(Contact.TEL, 0);
            System.out.println("Phone " + mobile);

            if (contact.countValues(Contact.TEL) > 1)
                mobile1 = contact.getString(Contact.TEL, 1);
            System.out.println("Phone " + mobile1);

            if (contact.countValues(Contact.TEL) > 2)
                mobile2 = contact.getString(Contact.TEL, 2);
            System.out.println("Phone " + mobile2);
        } catch (Exception e) {
            System.out.println("Exception::" + e.getMessage());
        }
        if (contacts.isSupportedField(Contact.ADDR)) {

            try {
                address = "";
                String[] addressarr = contact.getStringArray(
                        BlackBerryContact.ADDR, 0);

                for (int i = 0; i < addressarr.length; i++) {

                    if (addressarr[i] != null) {
                        address = address + " " + addressarr[i];

                    }

                }
                System.out.println("Address==" + address);

                address1 = "";
                String[] addressar = contact.getStringArray(
                        BlackBerryContact.ADDR, 1);

                for (int i = 0; i < addressar.length; i++) {

                    if (addressar[i] != null) {
                        address1 = address1 + " " + addressar[i];

                    }

                }
                System.out.println("Address==" + address1);
            } catch (Exception e) {
                System.out.println("Exception::" + e.getMessage());
            }

            timeStamp = DateTimeUtil.timestamp();

            try {
                System.out.println("Entering into the db");
                dbconnectVity.setDataBase();
                Contactlistdatabasetable Contactlist;
                Contactlist = new Contactlistdatabasetable(
                        "Contacts", "Delete", firstname, lastname, mobile,
                        mobile1, mobile2, email, email1, web, company,
                        address, address1, timeStamp);
                ContactlistdatabaseQueries.insertSingleContactlist(Contactlist);
                ContactlistdatabaseQueries.selectWholeContactlist();
            } catch (Exception e) {
                System.out.println("Exception::" + e.getMessage());
            }

            return;
        }
    }

}

public void itemUpdated(PIMItem arg0, PIMItem arg1) {
    System.out.println("Item Updated ==");
    String firstname = "none";
    String lastname = "none";
    String mobile = "none";
    String mobile1 = "none";
    String mobile2 = "none";
    String email = "none";
    String email1 = "none";
    String web = "none";
    String company = "none";
    String address = "none";
    String address1 = "none";
    String name[] = { "" };
    String timeStamp = "none";

    PIMList contacts = arg1.getPIMList();
    Contact contact = (Contact) arg1;

    if (contacts.isSupportedField(Contact.NAME)) {

        try {
            if (contact.countValues(Contact.NAME) > 0)
                name = contact.getStringArray(Contact.NAME, 0);
            if (name[Contact.NAME_GIVEN] != null)
                firstname = name[Contact.NAME_GIVEN];
            System.out.println("FirstName= " + firstname);
            if (name[Contact.NAME_FAMILY] != null)
                lastname = name[Contact.NAME_FAMILY];
            System.out.println("LastName= " + lastname);
        } catch (Exception e) {
            System.out.println("Exception::" + e.getMessage());
        }

    }
    if (contacts.isSupportedField(Contact.EMAIL)) {
        try {
            if (contact.countValues(Contact.EMAIL) > 0)
                email = contact.getString(Contact.EMAIL, 0);
            System.out.println("Email " + email);

            if (contact.countValues(Contact.EMAIL) > 1)
                email1 = contact.getString(Contact.EMAIL, 1);
            System.out.println("Email " + email1);
        } catch (Exception e) {
            System.out.println("Exception::" + e.getMessage());
        }
    }

    if (contacts.isSupportedField(Contact.ORG)) {

        try {
            if (contact.countValues(Contact.ORG) > 0)
                company = contact.getString(Contact.ORG, 0);
            System.out.println("Company " + company);
        } catch (Exception e) {
            System.out.println("Exception::" + e.getMessage());
        }
    }

    if (contacts.isSupportedField(Contact.URL)) {
        try {
            if (contact.countValues(Contact.URL) > 0)
                web = contact.getString(Contact.URL, 0);
            System.out.println("web " + web);
        } catch (Exception e) {
            System.out.println("Exception::" + e.getMessage());
        }
    }
    if (contacts.isSupportedField(Contact.TEL)) {
        try {
            if (contact.countValues(Contact.TEL) > 0)
                mobile = contact.getString(Contact.TEL, 0);
            System.out.println("Phone " + mobile);

            if (contact.countValues(Contact.TEL) > 1)
                mobile1 = contact.getString(Contact.TEL, 1);
            System.out.println("Phone " + mobile1);

            if (contact.countValues(Contact.TEL) > 2)
                mobile2 = contact.getString(Contact.TEL, 2);
            System.out.println("Phone " + mobile2);
        } catch (Exception e) {
            System.out.println("Exception::" + e.getMessage());
        }
        if (contacts.isSupportedField(Contact.ADDR)) {

            try {
                address = "";
                String[] addressarr = contact.getStringArray(
                        BlackBerryContact.ADDR, 0);

                for (int i = 0; i < addressarr.length; i++) {

                    if (addressarr[i] != null) {
                        address = address + " " + addressarr[i];

                    }

                }
                System.out.println("Address==" + address);
                address1 = "";
                String[] addressar = contact.getStringArray(
                        BlackBerryContact.ADDR, 1);

                for (int i = 0; i < addressar.length; i++) {
                    if (addressar[i] != null) {
                        address1 = address1 + " " + addressar[i];

                    }

                }
                System.out.println("Address==" + address1);
            } catch (Exception e) {
                System.out.println("Exception::" + e.getMessage());
            }

            timeStamp = DateTimeUtil.timestamp();

            try {
                System.out.println("Entering into the db");
                dbconnectVity.setDataBase();
                Contactlistdatabasetable Contactlist;
                Contactlist = new Contactlistdatabasetable(
                        "Contacts", "Update", firstname, lastname, mobile,
                        mobile1, mobile2, email, email1, web, company,
                        address, address1, timeStamp);
                ContactlistdatabaseQueries.insertSingleContactlist(Contactlist);
                ContactlistdatabaseQueries.selectWholeContactlist();

            } catch (Exception e) {
                System.out.println("Exception::" + e.getMessage());
            }

            return;

        }
    }

}

}

i hope u have understood my problem

when i have selected "ContactlistdatabaseQueries.selectWholeContactlist();" this method in any main class i am not able to fetch the data in the database, the response when i am getting is 0. but i need to get the value of the stored data i.e number of rows inserted.

A: 

Hi

i have got my problem sloved it is nothing but just changing the database, ihave used perstlite in the issue but persistent will be the better one for the above problem

jagadesh