Android: sqlite querying based on username

public ArrayList < PatientInfo > getAllPatients(String username) {
    ArrayList < PatientInfo > patients = new ArrayList < PatientInfo > ();

    open();

    Cursor cursor = db.query(UserTable, null, null, null, null, null, AccessedDate);
    while (cursor != null && cursor.moveToNext()) {
        try {

        } catch (Exception ex) {
            //Log.e("XXX", ex.getMessage());
        }
    }
    if (cursor != null)
        cursor.close();
    close();

    Collections.reverse(patients);
    return patients;
}

I am getting username as argument in my method, how can i query out my table based on username and get the user specific result.

Answers


As you can see from the documentation, the third and fourth parameters to query() are the selection and selection args.

So you want something like this:

 Cursor cursor = db.query(UserTable, null, 
                          "username=?", new String[] {username}, 
                          null, null, AccessedDate);

Edit the third parameter as needed to match the actual name of the relevant column in your table.


Need Your Help

NSSet of NSNumbers - member method is always nil

objective-c contains nsnumber nsset

I want to have a simple NSSet which is loaded with some NSNumbers and then find out if those numbers are already added in the set or not. When I do this: NSMutableSet *set = [[NSMutableSet alloc]

Why subscriptions interact with each other?

c# system.reactive

I am experimenting with RX, and run across the following problem (at least I perceive it as a problem). The following code creates an observable, and subscribes to it twice. I thought subscriptions

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.