public ContactDetails updateContact(ContactDetails contactDetail,
			ContactPhoto contactPhoto, Connection connection) {
		// TODO Auto-generated method stub

		try {
			int flag = 0;
			int contactId = contactDetail.getContactId();
			ContactDetails contactDetailTemp = new ContactDetails();
			contactDetailTemp.setContactId(contactId);
			contactDetailTemp = getContact(contactDetailTemp, connection);
			if (contactDetailTemp.getContactId() == 0) {

				contactDetailTemp.setContactId(0);
				return contactDetailTemp;

			} else {
				String firstName = contactDetail.getFirstName();
				String lastName = contactDetail.getLastName();
				String physicalAddress = contactDetail.getPhysicalAddress();
				long phoneNumber = contactDetail.getPhoneNumber();
				String emailId = contactDetail.getEmailId();
				InputStream uploadedPhoto = contactPhoto.getUploadedPhoto();
				Statement statement = connection.createStatement();
				ResultSet rs = statement
						.executeQuery("select phonenumber from contactregister where contactid <> '"
								+ contactId + "'");
				while (rs.next()) {
					if (phoneNumber == rs.getLong(1)) {
						System.out.println(phoneNumber + "," + rs.getLong(1));
						flag = 1;
					}
				}
				System.out.println(flag);
				if (flag == 0) {
					String sql = "update contactregister set firstname = ?,lastname = ?, physicaladdress = ?, phonenumber =?, emailid = ?, contactphoto = ? where contactid = ?";
					PreparedStatement statement1 = connection
							.prepareStatement(sql);

					statement1.setString(1, firstName);
					statement1.setString(2, lastName);
					statement1.setString(3, physicalAddress);
					statement1.setLong(4, phoneNumber);
					statement1.setString(5, emailId);
					statement1.setBlob(6, uploadedPhoto);
					statement1.setInt(7, contactId);
					System.out.println(sql);
					int a = statement1.executeUpdate();

					System.out.println(a);
					if (a > 0) {
						contactDetail.setContactId(contactId);
					} else if (a == 0) {
						contactDetail.setContactId(-2);
					}
				} else {
					contactDetail.setContactId(-1);
				}
			}

		} catch (SQLException sqle) {

		} catch (Exception e) {

		}
		return contactDetail;

	}