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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:24:07+00:00 2026-06-15T05:24:07+00:00

Im trying select specific fields from my database that would match the item that

  • 0

Im trying select specific fields from my database that would match the item that was clicked in my listview, when i run the app and clicked any item a app crashes, What is wrong in my code?

Here is the error from logcat

11-28 16:08:50.168: E/AndroidRuntime(27284): FATAL EXCEPTION: main
11-28 16:08:50.168: E/AndroidRuntime(27284): android.database.sqlite.SQLiteException: near "General": syntax error: , while compiling: SELECT Region,City,Address,Contact FROM tblHospitals WHERE HospitalName = Bernardino General Hospital
11-28 16:08:50.168: E/AndroidRuntime(27284):    at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
11-28 16:08:50.168: E/AndroidRuntime(27284):    at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java)
11-28 16:08:50.168: E/AndroidRuntime(27284):    at android.database.sqlite.SQLiteProgram.compileSql(SQLiteProgram.java)
11-28 16:08:50.168: E/AndroidRuntime(27284):    at android.database.sqlite.SQLiteProgram.compileAndbindAllArgs(SQLiteProgram.java)
11-28 16:08:50.168: E/AndroidRuntime(27284):    at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java)
11-28 16:08:50.168: E/AndroidRuntime(27284):    at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java)
11-28 16:08:50.168: E/AndroidRuntime(27284):    at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java)
11-28 16:08:50.168: E/AndroidRuntime(27284):    at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java)
11-28 16:08:50.168: E/AndroidRuntime(27284):    at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java)
11-28 16:08:50.168: E/AndroidRuntime(27284):    at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java)
11-28 16:08:50.168: E/AndroidRuntime(27284):    at com.dr.droid.lee.Health.onListItemClick(Health.java:54)
11-28 16:08:50.168: E/AndroidRuntime(27284):    at android.app.ListActivity$2.onItemClick(ListActivity.java)
11-28 16:08:50.168: E/AndroidRuntime(27284):    at android.widget.AdapterView.performItemClick(AdapterView.java:292)
11-28 16:08:50.168: E/AndroidRuntime(27284):    at android.widget.AbsListView.performItemClick(AbsListView.java:1071)
11-28 16:08:50.168: E/AndroidRuntime(27284):    at android.widget.AbsListView$PerformClick.run(AbsListView.java:2527)
11-28 16:08:50.168: E/AndroidRuntime(27284):    at android.widget.AbsListView$1.run(AbsListView.java:3181)
11-28 16:08:50.168: E/AndroidRuntime(27284):    at android.os.Handler.handleCallback(Handler.java)
11-28 16:08:50.168: E/AndroidRuntime(27284):    at android.os.Handler.dispatchMessage(Handler.java)
11-28 16:08:50.168: E/AndroidRuntime(27284):    at android.os.Looper.loop(Looper.java)
11-28 16:08:50.168: E/AndroidRuntime(27284):    at android.app.ActivityThread.main(ActivityThread.java)
11-28 16:08:50.168: E/AndroidRuntime(27284):    at java.lang.reflect.Method.invokeNative(Native Method)
11-28 16:08:50.168: E/AndroidRuntime(27284):    at java.lang.reflect.Method.invoke(Method.java:511)
11-28 16:08:50.168: E/AndroidRuntime(27284):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java)
11-28 16:08:50.168: E/AndroidRuntime(27284):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java)
11-28 16:08:50.168: E/AndroidRuntime(27284):    at dalvik.system.NativeStart.main(Native Method)

Here is my class file

public class Health extends ListActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.health);
        displayHospitals();
        }

    public void displayHospitals (){
        final ListView lv = getListView();
        DbHelper tblHL = new DbHelper(this);
        tblHL.open();
        ArrayList<String> result = tblHL.getHData();
        result = tblHL.getHData();
        setListAdapter(new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, result));
        lv.setTextFilterEnabled(true);

         tblHL.close();
         }

    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
        // TODO Auto-generated method stub
        super.onListItemClick(l, v, position, id);
        String hosp = (String)getListAdapter().getItem(position);
        String quer = "SELECT Region,City,Address,Contact FROM tblHospitals WHERE HospitalName = " +hosp ;
        SQLiteDatabase mydb = openOrCreateDatabase("dbDrDroid", MODE_PRIVATE, null);
        Cursor c = mydb.rawQuery(quer, null);
        c.moveToFirst();
        Toast.makeText(this, c.toString(), Toast.LENGTH_SHORT).show();
        }


}
  • 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-15T05:24:08+00:00Added an answer on June 15, 2026 at 5:24 am

    I think you need to do like this to make sure that your query handles the spaces in the hospital name correctly:

    String quer = "SELECT Region,City,Address,Contact FROM tblHospitals WHERE HospitalName = \"" +hosp + "\"";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When trying to select fields from a subquery if ANY of the subqueries do
I am trying to select payment plans for a specific term from my database.
I'm trying to use LINQ to SQL to select a few specific columns from
In trying to select elements that have any attributes, the following throws a jQuery
I'm trying to select all text in-between following a specific pattern: Sample Text: by
I am trying to use a hashtable so I can select a specific object
I am trying to select three values from xml document. I want to get
I am trying to select the last record from a table in MySQL using
I am trying to select an object from this array and print all of
I'm trying to select all fields in two separate tables as long as they're

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.