0
我創建了SQL查詢從表中獲取數據價格,其中我從表日誌傳遞4個參數。我想檢索4個價格值。
我在我的Logs類中創建了這個,我傳遞的參數是Logs getters。
我可能搞砸了sql查詢。 之後,我需要解析成double和multiply方法getResult()。
我的問題是如何正確地創建此sql查詢並解析它爲double或int?
這是我的代碼。請幫忙。如何解析從sql查詢收到的數據到雙重
public double getResult() {
double log_length, log_diameter, length, diameter, result;
log_length = Integer.parseInt(getLength().toString());
log_diameter = Integer.parseInt(getDiameter().toString());
length = log_length/100;
diameter = log_diameter * log_diameter * 3.14159265;
result = length * diameter/40000;
return result;
}
public Cursor getPrice() {
Cursor cursor = db.query("Price", new String[]{"price_stump_kn", "price_stump_eur", "road_price_kn", "road_price_eur"}, "sort = ? AND grade = ? AND length = ? BETWEEN diameter_dg = ? AND diameter_gg = ?",
new String[]{getSort_id(), getGrade(), getLength(), getDiameter(), getDiameter()}, null, null, null);
if (cursor.moveToFirst()) {
do {
Price price = new Price();
price.setStumpPrice_kn(cursor.getString(0));
price.setStumpPrice_eur(cursor.getString(1));
price.setRoadPrice_kn(cursor.getString(2));
price.setRoadPrice_eur(cursor.getString(3));
} while (cursor.moveToNext());
}
return cursor;
}
剛纔編輯與新代碼的問題。我改變我的價格方法。但它不好。我需要獲得所有4個價格,並用getResult()方法將每個價格乘以。 – RubyDigger19
@ RubyDigger19不要改變問題;這會使答案無效。如果此答案解決了您的原始問題,請接受它。如果您有其他問題,請提出一個新問題。 –
好的,它有幫助。我會接受你的回答。但我可以問你如何從遊標獲取解析值並在其他方法中使用它們? – RubyDigger19