i’m currently trying to get a single row from my own database, located in the assets folder. Checking if there is a row in the table, with the SQLite Query Browser and the SELECT-Statement from the debugger got me a single row in the database. Anyway calling the statement from my code just gets me an empty cursor. I also added the method
cursor.moveToFirst()
and avoided calling
myDataBase.close();
Here is the method where i’m trying to append a single entry on a TextView:
private void getAdresses(Location location) { // TODO
double lat = location.getLatitude();
double lng = location.getLongitude();
Geocoder geocoder = new Geocoder(this, Locale.GERMAN);
try {
List<Address> addresses = geocoder.getFromLocation(lat, lng, 1);
if (addresses.size() != 0) {
Address address = addresses.get(0);
String addressString = address.getAddressLine(0).toString();
System.out.println("(geocoder) " + addressString);
textView.append(addressString + "\n");
Cursor cursor = mDbHelper.getAllEntrys("tblBar", "Adresse",
addressString);
if (cursor.moveToFirst()) {
String cursorContent = cursor.getString(cursor
.getColumnIndexOrThrow("Name"));
textView.append(cursorContent + "\n");
} else {
System.out.println("No bar at current location");
}
} else {
System.out.println("(geocoder) no address!");
}
} catch (IOException e) {
System.out.println(e.toString() + "(geocoder)");
}
}
Furthermore this is my method for calling the actual query on the database:
public Cursor getAllEntrys(String table, String column, String search) {
try {
String sSelect = "SELECT * FROM " + table + " WHERE " + column
+ " = '" + search + "'";
Cursor cursor = mDb.rawQuery(sSelect, null);
if (cursor != null) {
cursor.moveToFirst();
}
return cursor;
} catch (SQLException mSQLException) {
System.out.println("getData >>" + mSQLException.toString());
throw mSQLException;
}
}
Hope someone can help me with this. Many thanks in advance!
Okay guys first i want to thank all of you for your quick responses. Keep it up! Although the answer is quite obvious, i figured it out myself. The problem in the tutorial from: http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/ is, that it doesn’t consider the case that you add values manually (Updates in the SQLite Database Browser) to your database after you first run the programm. Thats what i did… So you have to write your own method to check if there were any changes since the last run. Hope anyone can need this 🙂