# android.database.sqlite.SQLiteException: near "?": syntax error (code 1): , while compiling: SELECT * FROM users WHERE id = ? AND name = ?

- **ID:** `android/room-query-parameter-mismatch`
- **Domain:** android
- **Category:** runtime_error
- **Error Code:** `1`
- **Verification:** ai_generated
- **Fix Rate:** 95%

## Root Cause

The number of parameters in a Room @Query does not match the number of method arguments, causing a SQL syntax error.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Room 2.4.0 | active | — | — |
| Room 2.5.0 | active | — | — |
| Room 2.6.0 | active | — | — |

## Workarounds

1. **Ensure the number of '?' placeholders in the SQL query matches the number of method parameters. Example: If method is 'fun getUser(id: Int, name: String): User?', the query should be 'SELECT * FROM users WHERE id = ? AND name = ?'.** (95% success)
   ```
   Ensure the number of '?' placeholders in the SQL query matches the number of method parameters. Example: If method is 'fun getUser(id: Int, name: String): User?', the query should be 'SELECT * FROM users WHERE id = ? AND name = ?'.
   ```
2. **Use named bind parameters with ':paramName' syntax for clarity and to avoid count mismatches. Example: 'SELECT * FROM users WHERE id = :id AND name = :name'.** (90% success)
   ```
   Use named bind parameters with ':paramName' syntax for clarity and to avoid count mismatches. Example: 'SELECT * FROM users WHERE id = :id AND name = :name'.
   ```
3. **Run Room's annotation processor (kapt or ksp) to generate validation errors at compile time that catch parameter mismatches.** (85% success)
   ```
   Run Room's annotation processor (kapt or ksp) to generate validation errors at compile time that catch parameter mismatches.
   ```

## Dead Ends

- **** — The SQL query still has fewer placeholders than arguments, causing a mismatch error. (80% fail)
- **** — This introduces SQL injection risk and does not fix the parameter count issue. (90% fail)
