Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7181727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:37:05+00:00 2026-05-28T17:37:05+00:00

I have created an application in Android that needs to send emails to all

  • 0

I have created an application in Android that needs to send emails to all contacts saved in the database as you click on a SendMailbutton, to sending email to each contact with respective score,

the idea was to slide the couples (email,score) of each user in the database and pass it to a specific method that sends the email

I implemented the send method in order to receive the email address and the score associated
I tested the send eMail method and works properly,

The only problem is that I can not define a way suitable for
pass all the email address and the associated scores of each user at the click of the button.

My DatabaseHelper class is the follow:

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;




public class DatabaseHelper extends SQLiteOpenHelper {

static final String dbName="demoDB";
static final String PlayerTable="Players";
static final String colID="PlayerID";
static final String colName="PlayerName";
static final String colEmail="Email";
static final String colScore="Score";
static final String colDept="Dept";

static final String deptTable="Dept";
static final String colDeptID="DeptID";
static final String colDeptName="DeptName";

static final String viewEmps="ViewEmps";


public DatabaseHelper(Context context) {
    super(context, dbName, null,33);

    // TODO Auto-generated constructor stub
}

@Override
public void onCreate(SQLiteDatabase db) {
    // TODO Auto-generated method stub

    db.execSQL("CREATE TABLE "+deptTable+" ("+colDeptID+ " INTEGER PRIMARY KEY , "+
            colDeptName+ " TEXT)");

    db.execSQL("CREATE TABLE "+PlayerTable+" ("+colID+" INTEGER PRIMARY KEY AUTOINCREMENT, "+
            colName+" TEXT, "+colEmail+" TEXT, "+colScore+" Integer, "+colDept+" INTEGER NOT NULL ,FOREIGN KEY ("+colDept+") REFERENCES "+deptTable+" ("+colDeptID+"));");


    db.execSQL("CREATE TRIGGER fk_empdept_deptid " +
            " BEFORE INSERT "+
            " ON "+PlayerTable+

            " FOR EACH ROW BEGIN"+
            " SELECT CASE WHEN ((SELECT "+colDeptID+" FROM "+deptTable+" WHERE "+colDeptID+"=new."+colDept+" ) IS NULL)"+
            " THEN RAISE (ABORT,'Foreign Key Violation') END;"+
            "  END;");

    db.execSQL("CREATE VIEW "+viewEmps+
            " AS SELECT "+PlayerTable+"."+colID+" AS _id,"+
            " "+PlayerTable+"."+colName+","+
            " "+PlayerTable+"."+colEmail+","+
            " "+PlayerTable+"."+colScore+","+
            " "+deptTable+"."+colDeptName+""+
            " FROM "+PlayerTable+" JOIN "+deptTable+
            " ON "+PlayerTable+"."+colDept+" ="+deptTable+"."+colDeptID
            );
    //Inserts pre-defined sections
    InsertDepts(db);

}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    // TODO Auto-generated method stub

    db.execSQL("DROP TABLE IF EXISTS "+PlayerTable);
    db.execSQL("DROP TABLE IF EXISTS "+deptTable);

    db.execSQL("DROP TRIGGER IF EXISTS dept_id_trigger");
    db.execSQL("DROP TRIGGER IF EXISTS dept_id_trigger22");
    db.execSQL("DROP TRIGGER IF EXISTS fk_empdept_deptid");
    db.execSQL("DROP VIEW IF EXISTS "+viewEmps);
    onCreate(db);
}

 void AddPlayer(Player emp)
{


     SQLiteDatabase db= this.getWritableDatabase();


    ContentValues cv=new ContentValues();

    cv.put(colName, emp.getName());
    cv.put(colName, emp.getEmail());
    cv.put(colScore, emp.getScore());
    cv.put(colDept, emp.getDept());
    //cv.put(colDept,2);

    db.insert(PlayerTable, colName, cv);
    db.close();


}

 int getPlayerCount()
 {
    SQLiteDatabase db=this.getWritableDatabase();
    Cursor cur= db.rawQuery("Select * from "+PlayerTable, null);
    int x= cur.getCount();
    cur.close();
    return x;
 }

 Cursor getAllPlayers()
 {
     SQLiteDatabase db=this.getWritableDatabase();



     //Cursor cur= db.rawQuery("Select "+colID+" as _id , "+colName+", "+colEmail+","+colScore+" from "+PlayerTable, new String [] {});
     Cursor cur= db.rawQuery("SELECT * FROM "+viewEmps,null);
     return cur;

 }

 Cursor getAllDepts()
 {
     SQLiteDatabase db=this.getReadableDatabase();
     Cursor cur=db.rawQuery("SELECT "+colDeptID+" as _id, "+colDeptName+" from "+deptTable,new String [] {});

     return cur;
 }

 void InsertDepts(SQLiteDatabase db)
 {
     ContentValues cv=new ContentValues();
        cv.put(colDeptID, 1);
        cv.put(colDeptName, "Sales");
        db.insert(deptTable, colDeptID, cv);
        cv.put(colDeptID, 2);
        cv.put(colDeptName, "IT");
        db.insert(deptTable, colDeptID, cv);
        cv.put(colDeptID, 3);
        cv.put(colDeptName, "HR");
        db.insert(deptTable, colDeptID, cv);
        db.insert(deptTable, colDeptID, cv);

 }

 public String GetDept(int ID)
 {
     SQLiteDatabase db=this.getReadableDatabase();

     String[] params=new String[]{String.valueOf(ID)};
     Cursor c=db.rawQuery("SELECT "+colDeptName+" FROM"+ deptTable+" WHERE "+colDeptID+"=?",params);
     c.moveToFirst();
     int index= c.getColumnIndex(colDeptName);
     return c.getString(index);
 }

 public Cursor getEmpByDept(String Dept)
 {
     SQLiteDatabase db=this.getReadableDatabase();
     String [] columns=new String[]{"_id",colName,colEmail,colScore,colDeptName};
     Cursor c=db.query(viewEmps, columns, colDeptName+"=?", new String[]{Dept}, null, null, null);
     return c;
 }

 public int GetDeptID(String Dept)
 {
     SQLiteDatabase db=this.getReadableDatabase();
     Cursor c=db.query(deptTable, new String[]{colDeptID+" as _id",colDeptName},colDeptName+"=?", new String[]{Dept}, null, null, null);
     //Cursor c=db.rawQuery("SELECT "+colDeptID+" as _id FROM "+deptTable+" WHERE "+colDeptName+"=?", new String []{Dept});
     c.moveToFirst();
     return c.getInt(c.getColumnIndex("_id"));

     }

 public int UpdateEmp(Player emp)
 {
     SQLiteDatabase db=this.getWritableDatabase();
     ContentValues cv=new ContentValues();
     cv.put(colName, emp.getName());
     cv.put(colScore, emp.getScore());
     cv.put(colDept, emp.getDept());
     return db.update(PlayerTable, cv, colID+"=?", new String []{String.valueOf(emp.getID())});

 }

 public void DeleteEmp(Player emp)
 {
     SQLiteDatabase db=this.getWritableDatabase();
     db.delete(PlayerTable,colID+"=?", new String [] {String.valueOf(emp.getID())});
     db.close();



 }

}

Help me please.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T17:37:06+00:00Added an answer on May 28, 2026 at 5:37 pm
    1. Create getScores returning HashMap in your dbHelper class

      public HashMap<String,String> getScores() {
      HashMap<String,String> list = new HashMap<String,String>();
      SQLiteDatabase db=this.getReadableDatabase();
      Cursor cursor = db.rawQuery("Select email,sum(score) from players group by Email",null);
          if (cursor.moveToFirst()) {
              do {
                  list.put(cursor.getString(0),cursor.getString(1));
              } while (cursor.moveToNext());
          }
          if (cursor != null && !cursor.isClosed()) {
              cursor.close();
          }
      return list;}
      
    2. use this method to send emails assuming

    sendMail(String mailTo,String score);


    HashMap<String,String> scores = dbHelper.getScores();
    for(Map.Entry entry : scores.entrySet())
    {
         sendMail(entry.getKey(),entry.getValue());
    }
    

    hope this helps to clarify it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem with my Android application. I need an application that will send
I have created an application for Android that has an activity that has a
I have created an application which needs 'hand-over' to the support group in the
I have created an application that writes some data to the root folder of
I have created an application that runs in the taskbar. When a user clicks
I have created an application that has a toolbar, menubar and content area. I
I have created an application in facebook,all is working fine except the publish to
I have created an application using Adobe Flex. I took all the files from
I have created an application which needs to have a profile box tab which
I have created an application that uses settings.settings to store some user specific settings

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.