I want to know how to pass a value that was retrieve from the Column numbers in my database class, which is the DBUser.java, and assign it to a variable to another class?.
I’ve tried this method in my DBUser.java:
public String getNumber() throws SQLException
{
String number;
Cursor mCursor = db.query(DATABASE_TABLE, new String[] {KEY_NUMBER}, null, null, null, null, null);
number = mCursor.getString(mCursor.getColumnIndex(KEY_NUMBER)); // KEY_NUMBER ="numbers"
mCursor.close();
return number; // I think I'm missing something here???? IDK
}
And this is the method in my main class which I would like to pass the value of the column numbers:
public void onACU (View view) {
String messageToSend = "ACU ON";
DBUser dbUser = new DBUser(AleccMainActivity.this);
dbUser.open(); // I opened the DB
// recipient is a global variable.
recipient = dbUser.getNumber();//then I assigned the method in my string var thinking that the value will be passed to it.
dbUser.close(); // then i close the DB
SmsManager.getDefault().sendTextMessage(recipient, null, messageToSend, null,null);
}
My instincts tell me that my db.query and return statement doesn’t seem right so please do tell me on how to get it working.
I’m new to java though. thanks!
Even if the cursor has only one row, you have to call moveToFirst() or moveToNext().