我正在从SQLite数据库中检索纬度数据。
我有一张充满经度和纬度值的表格。
我的查询是:
public Cursor fetchAllCountries() {
SQLiteDatabase db=this.getReadableDatabase();
String SelectQuery="select * from "+ TABLE_NAME;
Cursor mCursor = db.rawQuery(SelectQuery,null);
if (mCursor != null) {
mCursor.moveToFirst();
}
return mCursor;
}
我的MainActivity.java
包含:
Cursor cursor = myDB.fetchAllCountries();
/* for (int i=0;i<list.size();i++) {
double data=list.get(i);
System.out.println(data + " ");
}*/
if (cursor.moveToFirst()) {
do {
double data = cursor.getDouble(cursor.getColumnIndex("lat"));
System.out.println(data + " ");
} while(cursor.moveToNext());
}
答案 0 :(得分:0)
public Cursor fetchAllCountries() {
SQLiteDatabase db=this.getReadableDatabase();
String SelectQuery="select * from "+ TABLE_NAME;
Cursor mCursor = db.rawQuery(SelectQuery,null);
if (mCursor != null) {
mCursor.moveToFirst();
}
return mCursor;
}
MainActivity.java
TextView txt = (TextView) findViewById(R.id.textView);
Cursor cursor = myDB.fetchAllCountries();
double[] array = new double[cursor.getCount()];
int i = 0;
if (cursor.moveToFirst()) {
do {
double data = cursor.getDouble(cursor.getColumnIndex("lat"));
array[i] = data;
txt.append(Double.toString(array[i]));
i++;
} while (cursor.moveToNext());
}
答案 1 :(得分:-1)
这是一个例子。
private static List<Information> getAllInformation(Cursor cursor) {
List<Information> list = new ArrayList<>();
if (cursor != null) {
if (cursor.moveToFirst()) {
do {
int id = cursor.getInt(cursor.getColumnIndex(COL_ID));
String title = cursor.getString(cursor.getColumnIndex(COL_TITLE));
String mediaName = cursor.getString(cursor.getColumnIndex(COL_MEDIA_NAME));
Information info = new Information(id, title, mediaName);
list.add(info);
} while (cursor.moveToNext());
}
if (!cursor.isClosed()) {
cursor.close();
}
}
return list;
}
public static List< Information > getAllInformation() {
String sql = "SELECT * FROM " + TABLE_NAME;
SQLiteDatabase database = this.getReadableDatabase();
Cursor cursor = database.rawQuery(sql, null);
return getAllInformation(cursor);
}
在活动中
List<Information> mListAll;
mListAll = YourNameTable.getAllInformation();
Class Information.class
public class Information {
int id;
String title;
String mediaName;
//get
//set
}