Я пытался последние три дня, но мне не удалось решить эту проблему, редактировал таблицы и запросы.
Я использовал перстлит для хранения данных;Я создал таблицы и запросы для требуемого класса;
Теперь я прослушиваю контакты в мобильном телефоне и могу получать данные только в этом классе, но не могу получить информацию восновной класс или где-нибудь в проекте, хотя я назвал класс.Кто-нибудь может мне помочь с этой проблемой?
Это моя программа
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., но мне нужно получить значение сохраненных данных, то есть количество вставленных строк.