Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
Posts: 43
Registered: ‎07-22-2012
My Device: curve
My Carrier: syudent

What's wrong in the cursor return type of this function

i have fuction that return cursor 

public Cursor getAllCounries() {
		Statement st = null;
		try {
			st = db.createStatement("select [" + KEY_COUNTRY_ID + "],["
					+ KEY_COUNTRY_Name + "],[" + KEY_COUNTRY_CURRENCY
					+ "] From [" + DATABASE_TABLE_COUNTRY + "] order by ["
					+ KEY_COUNTRY_Name + "]");
			st.prepare();
			Cursor c = st.getCursor();
			return c;
		} catch (Exception e) {
			return null;
		} finally {
			try {
				st.close();
			} catch (Exception e) {
			}
		}
	}

 but when i call the function the cursor is unll although he select data and if i use cursor in the function work right and cursor not null but when call it return cursor but have problem please anybody help me

New Contributor
Posts: 4
Registered: ‎09-16-2012
My Device: Simulator
My Carrier: MTS

Re: What's wrong in the cursor return type of this function

Do not not close the statement before you read and close the cursor.
In your code finally block executes before you function returns the cursor so it returns with closed statement.