Reputation: 1171
Android SQLLite gives me the following error:
SQLiteStatement tgStatement = dbo.compileStatement("INSERT OR REPLACE INTO Game_Team" +
"(teamId, gameId, pos, score) VALUES (?,?,?,?) ");
Thats why I try to do:
tgStatement.bindLong(0, 1);
I get an error
java.lang.IllegalArgumentException: Cannot bind argument at index 0 because the index is out of range.
The statement has 4 parameters.
So, my question is, if there are 4 parameters, why is it complaining about argument at index 0? how is that out of range?
Upvotes: 2
Views: 2217
Reputation: 7649
This trick might come handy to some.
SQLiteStatement tgStatement = dbo.compileStatement("INSERT OR REPLACE INTO Game_Team" +
"(teamId, gameId, pos, score) VALUES (?,?,?,?) ");
int i = 1;
tgStatement.bindLong(i++, teamId);
tgStatement.bindLong(i++, gameId);
tgStatement.bindString(i++, pos);
tgStatement.bindLong(i++, score);
Above trick is useful when you have more parameters, it avoid missing on indices as well as numbering them. i variable handles the indice.
Upvotes: 2
Reputation: 59112
The parameters are 1-indexed. The index needs to run from 1 to 4, so 0 is out of range.
Upvotes: 8