私は現在、資産フォルダーにある自分のデータベースから単一の行を取得しようとしています。SQLite Query Browser とデバッガーからの SELECT ステートメントを使用して、テーブルに行があるかどうかを確認すると、データベースに 1 つの行が作成されました。とにかく、私のコードからステートメントを呼び出すと、空のカーソルが表示されます。メソッドも追加しました
カーソル.moveToFirst()
呼び出しを避けた
myDataBase.close();
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)");
}
}
さらに、これはデータベースで実際のクエリを呼び出すための私の方法です:
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;
}
}
誰かがこれで私を助けてくれることを願っています。よろしくお願いします!