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

  • Home
  • SEARCH
  • 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 6707679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:40:06+00:00 2026-05-26T07:40:06+00:00

I’ve a database that I will populate with items after I parse a JSON

  • 0

I’ve a database that I will populate with items after I parse a JSON response. How can I check if the values are already present in the database and prevent inserting again ?

Eg. Name of Database: Exicom.sqlite

Name of table: TimeReport

Fields in Database: userID, clientName

I am using SQLite in android.

Thanks for your input

This is my HELPER class. I’ve skipped opening and closing the database as it will be too long. Followed up by where I will call the method to insert values into the database.

public static final String indexNo = "index_no";
public static final String user_id = "userId";
public static final String company_id = "companyId";
public static final String user_name = "username";
public static final String client_Id = "clientId";
public static final String project_Id = "projectId";
public static final String report_Id = "reportId";
public static final String niv_1  = "niv1";
public static final String niv_2 = "niv2";
public static final String work_type_id = "workTypeId";
public static final String time_type_id = "timeTypeId";
public static final String date_id = "dateId";
public static final String month_id = "monthId";
public static final String year_id = "yearId";
public static final String hourS = "hours";
public static final String private_comment = "privateComment";
public static final String Ncomment = "comment";
public static final String mod_flag = "modFlag";
public static final String new_flag = "newFlag";
public static final String open_flag = "openFlag";
public static final String delete_flag = "deleteFlag";

private static final String DATABASE_NAME = "CopernicusDB.sqlite";
private static final String DATABASE_TABLE = "TimeReportTable";
private static final int    DATABASE_VERSION = 1;

private final Context context;
private static DatabaseHelper DBHelper;
private static SQLiteDatabase db;
private static String TAG = "##---SecondActivityUserHelper---##";
public SecondActivityUserHelper(Context ctx)
{
this.context = ctx;
DBHelper = new DatabaseHelper(context);
}

private static class DatabaseHelper extends SQLiteOpenHelper{

    public DatabaseHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
        Log.v(TAG,"The DatabaseHelper method ");
    }

    public long insertIntoDatabase(String companyId,String username, String dateId,
            String clientId,String projectId,String niv1,String niv2,String workTypeId,String timeTypeId,
            String hours,String comment,String privateComment,String openFlag,String reportId) 
            {
            ContentValues initialValues = new ContentValues();
            initialValues.put(company_id, companyId);
            initialValues.put(user_name, username);
            initialValues.put(date_id,dateId);
            initialValues.put(client_Id,clientId);
            initialValues.put(project_Id,projectId);
            initialValues.put(niv_1,niv1);
            initialValues.put(niv_2,niv2);
            initialValues.put(work_type_id,workTypeId);
            initialValues.put(time_type_id,timeTypeId);
            initialValues.put(hourS, hours);
            initialValues.put(Ncomment, comment);
            initialValues.put(private_comment,privateComment);
            initialValues.put(open_flag, openFlag);
            initialValues.put(report_Id,reportId);
            Log.v(TAG, "Inserted into database sucessfully");
            return db.insert(DATABASE_TABLE, null, initialValues);
            }

}

useradapter.openDatabase();
long id = dB.insertIntoDatabase(  newcompanyid,newusername,newdate,
newClientId,newprojectId,newniv1,newniv2,newworktypeid,newtimetypeid,
newhours,newcomment,newprivatecomment,newopen,newreportid);
                             useradapter.closeDatabase();
  • 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-26T07:40:06+00:00Added an answer on May 26, 2026 at 7:40 am

    Create an object that will hold your data, eg. ClientData
    Create a method for fetching all data from the database

    public List<ClientData> selectAll() {
       List<ClientData> list = new ArrayList<ClientData>();
       Cursor cursor = this.myDataBase.query(TABLE_NAME, new String[] { "userID, clientName" },
       null, null, null, null, null);
       if (cursor.moveToFirst()) {
            do {
               list.add(new ClientData(cursor.getString(0), cursor.getString(1)));
             } while (cursor.moveToNext());
       }
       if (cursor != null && !cursor.isClosed()) {
             cursor.close();
       }
       return list;
    }
    

    Before executing your insert statements, fetch all data and then check if data exists:

    if (!list.contains(clientData)) {
        executeInsert();
    }
    

    I am not sure if SQLite supports stored procedures, but if it does, you could write a stored procedure for that as well.

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

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I've got a string that has curly quotes in it. I'd like to replace
i want to parse a xhtml file and display in UITableView. what is the

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.