there is a function, how to make it return the value of the query?
public void getMyMoney() throws SQLException { open(); String strSQL = "select SUM(operat_sum) as Costs from operations"; database.execSQL(strSQL); close(); } here are the open() & close methods
public void open() throws SQLException { database = dbHelper.getWritableDatabase(); } public void close() { dbHelper.close(); } so changed and throws out the java.lang.IllegalStateException error
public int getMyMoney2() throws SQLException { open(); int myMoney = 0; String strSQL = "select SUM(operat_sum) as Costs from operations"; Cursor c = database.rawQuery(strSQL, null); if (c.moveToFirst()) { // определяем номера столбцов по имени в выборке int idColIndex = c.getColumnIndex("operat_sum"); do { // получаем значения по номерам столбцов myMoney = c.getInt(idColIndex); Log.d(LOG_TAG, "COLUMN_OPERAT_SUM = " + c.getInt(idColIndex)); } while (c.moveToNext()); } close(); return myMoney; }
c.getColumnIndex("Costs")- temq