4

I'm trying to query on a table dormpolicy

String operatorName = "46001";
String selection = "(plmn = '"+operatorName+"')";
URI CONTENT_URI_DORMPOLICY = Uri.parse("content://nwkinfo/nwkinfo/dormpolicy");
cursor = phone.getContext.getContentResolver().query(CONTENT_URI_DORMPOLICY, null,      selection, null, null);

I get error log:

 SQLiteQuery: exception: no such table: dormpolicy; 

 query: SELECT * FROM dormpolicy  WHERE ((plmn = '46001'))

This issue happen not always in my phone.

It seems that sometimes,when I access the table before the table was created.

Is there any way that before I query the table, I check if the table exist?

And how?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
AndyGogo
  • 41
  • 1
  • 1
  • 2

1 Answers1

3

My answer is twofold:

  1. To strictly answer the question, I will redirect you to How does one check if a table exists in an Android SQLite database?

  2. But rather than manually checking for tables' existence, I suggest you use the SQLiteOpenHelper class. This will help you manage your tables in a structured way. That includes handling database upgrades. Have a look at this for a quick start: http://developer.android.com/guide/topics/data/data-storage.html#db

Community
  • 1
  • 1