Try to search your question here, if you can't find : Ask Any Question Now ?

How to search for possible match in specific row of table in database in android

HomeCategory: stackoverflowHow to search for possible match in specific row of table in database in android
Avatarpushpa asked 1 week ago

Hello I am Building an App and dealing with databases for the first time I am trying to get the data TEXT as input and search its match in the specific row. I have failed to do that.

I have got the specific row selected. I have six columns and I have got the specific row depending upon the id but comparing the Input Text in other five columns is giving problematic output.
With my approach given in the code below it is giving result after comparing it with the first or last column entry but not all.

    public Cursor finddata(String name,int ida, int guess){
        String Query = "SELECT  NAME1 FROM Capital_Names where ID = '" + ida + "' and NAME1='" +name+ "'";
                    cursor=db.rawQuery(Query,null);
                    check=1;
                    if(cursor==null){
                        String Query2 = "SELECT  NAME1 FROM Capital_Names where ID = '" + ida + "' and NAME2='" +name+ "'";
                        cursor=db.rawQuery(Query2,null);
                        check=2;
                    }
                    if(cursor==null){
                        String Query3 = "SELECT  NAME1 FROM Capital_Names where ID = '" + ida + "' and NAME3='" +name+ "'";
                        cursor=db.rawQuery(Query3,null);
                        check=3;
                    }
                    if(cursor==null){
                        String Query4 = "SELECT  NAME1 FROM Capital_Names where ID = '" + ida + "' and NAME4='" +name+ "'";
                        cursor=db.rawQuery(Query4,null);
                        check=4;
                    }
                    if(cursor==null){
                        String Query5 = "SELECT  NAME1 FROM Capital_Names where ID = '" + ida + "' and NAME5='" +name+ "'";
                        cursor=db.rawQuery(Query5,null);
                        check=5;
                    }
                    if(cursor==null){
                        String Query6 = "SELECT  NAME1 FROM Capital_Names where ID = '" + ida + "' and NAME6='" +name+ "'";
                        cursor=db.rawQuery(Query6,null);
                    }
                    return cursor;
                    }

I think there is some error in if condition that I am applying on the cursor as
“if(cursor==null)” because it is only giving the answer by comparing the first statement without if even if it is matching in first statement or not.

If there is some direct query statement to do that ?????

I have searched a lot on internet but could not find solution.
And please do not direct me to already answered questions and answer this question if you could.
Regards

1 Answers
Best Answer
AvatarFernando answered 1 week ago
Your Answer

9 + 1 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com