Search code examples
blackberrysqliteblackberry-jde

sqlite cursor behaviour


I am inserting values into table people, suppose if I enter 1,Ram,22,98; 1,Kri,22,83; 1,Sam,23,47;

While getting it back the the cursor is starting from 1,Sam,23,47; 1,Kri,22,83;
1,Ram,22,98; I am not able to figure out the error. any sort of help is welcome!

Create table People(id integer ,Name text,Age int,pplid primary key not null);

INSERT INTO People(id,Name,Age, pplid) VALUES (?,?,?,?); 

_statement = _dbTopNews.createStatement("Select * from People where id = 10;");
_statement.prepare();

Cursor _cursor = _statement.getCursor();
Row _row;
_vecTopNews = new Vector();

while(_cursor.next()){

_custObj = new CustomObj();
_row = _cursor.getRow();

_id = _row.getString(0);
_name = _row.getString(1);
_age = _row.getString(2);
_pplid = _row.getString(3);

_custObj.setID(_id );
_custObj.setName(_name );
_custObj.setAge(_age );
_custObj.setPplId(_pplid );

_vec = new Vector();

}

Solution

  • You should use id as index column, unique value for example 1,Ram,22,98; 2,Kri,22,83; 3,Sam,23,47 and then the sql statement will be "Select * from People where id = 10 ORDER by id;"