0

我从过去三天开始一直在尝试,但我无法解决这个问题;编辑表格和查询。

我一直在使用 perstlite 来存储数据;我已经为所需的类创建了表和查询;

现在我一直在听手机中的联系人,我只能在那个类中获取数据,但是我无法在主类或项目中的任何地方获取信息,尽管我已经调用了类。有人可以帮我解决这个问题吗?

这是我的程序

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;
            }
        }
    }
}

我希望你明白我的问题

当我选择了“ContactlistdatabaseQueries.selectWholeContactlist();” 这个方法在任何主类中我都无法获取数据库中的数据,我得到的响应是 0。但我需要获取存储数据的值,即插入的行数。

4

1 回答 1

0

我已经解决了我的问题,这只不过是更改数据库而已,我在问题中使用了 perstlite,但对于上述问题,持久性将是更好的选择

于 2010-07-22T04:51:51.297 回答