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 8142931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:57:26+00:00 2026-06-06T12:57:26+00:00

I’m in a mobile programming course right now and we need to create a

  • 0

I’m in a mobile programming course right now and we need to create a simple application where the user fills out a form and we take that data and record it in our own custom SQLite db. I’ve successfully made the form activity, with extensive error checking, and the ContentProvider to handle the database stuff. I’m pretty much completed, everything works right. I’m just struggling to add in this one last requirement- before we let the user submit his data for the form, we need to query the database and check if the username he’s adding already exists. If so, we notify him and don’t allow the database to be updated/created.

He’s some stuff from my content provider that describes the database:

public final static String DBNAME = "FormStorage";
public static final String AUTHORITY = "com.connor.black.provider";
public final static String TABLE_NAMESTABLE = "formstable";
private static UriMatcher sUriMatcher;

public final static String COLUMN_FIRSTNAME = "FirstName";
public final static String COLUMN_LASTNAME = "LastName";
public final static String COLUMN_PHONE = "PhoneNumber";
public final static String COLUMN_EMAIL = "Email";
public final static String COLUMN_USERNAME = "Username";
public final static String COLUMN_PASSWORD = "Password";
public final static String COLUMN_GENDER = "Gender";
public final static String COLUMN_COUNTRY = "Country";
public static final Uri CONTENT_URI = Uri.parse("content://com.connor.black.provider/" + TABLE_NAMESTABLE);


private static final String SQL_CREATE_MAIN = "CREATE TABLE " + TABLE_NAMESTABLE + "("+"_ID INTEGER PRIMARY KEY, "+
                                                                    "FirstName TEXT, " +
                                                                    "LastName TEXT, " +
                                                                    "PhoneNumber TEXT, " +
                                                                    "Email TEXT, " +
                                                                    "Username TEXT, " +
                                                                    "Password TEXT, " +
                                                                    "Gender TEXT, " +
                                                                    "Country TEXT)";

From my activity, in the submit onclicklister I’m doing this:

 final Cursor mCursor;
    submit.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {

            Boolean submitCheck = true;

                      //...and code goes by....//

//Username duplicate check
            String[] mProjection = new String[]{"FormStorage.formstable.Username"};
            mCursor = getContentResolver().query(MyContentProvider.CONTENT_URI,
                    mProjection, null, null, null);

if(mCursor != null) {
                if(mCursor.getCount() > 0) {

                   // Check if username already exists

                }
            }

So my question:

What should my mProjection string look like? I know the one I currently have is wrong, but I’m confused as to what the selection string should be?

  • 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-06-06T12:57:28+00:00Added an answer on June 6, 2026 at 12:57 pm

    Your projection is a String[] that holds column names as its elements. They should not contain any info about the particular tables. Note that it is the Uri’s job to identify the table (using the setTable method in your content provider’s query implementation).

    mProjection = new String { COLUMN_USERNAME }
    

    You should put your column values in a String[] and have them replace the ? in your selection String. This will protect your database from nasty SQL injections.

    mSelection = COLUMN_USERNAME + "= ?";
    mSelectionArgs = new String { "username" };
    

    Then perform the query with,

    Cursor cur = getContentResolver().query(CONTENT_URI, 
                                            mProjection, 
                                            mSelection, 
                                            mSelectionArgs, 
                                            null);
    

    Unless your table is small, you should be sure to perform the query on a separate thread. This will ensure that the UI thread isn’t blocked.

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

Sidebar

Related Questions

this is what i have right now Drawing an RSS feed into the php,
I need to clean up various Word 'smart' characters in user input, including but
Thanks in advance for your help. I have a need within an application to
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
In my XML file chapters tag has more chapter tag.i need to display chapters
I am doing a simple coin flipping experiment for class that involves flipping a

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.