This is the most effective defense. Instead of building a query string with user input, you use placeholders. The database treats the input strictly as data, not as executable code.
Ensure the data matches the expected format (e.g., an ID should only be an integer).
Ensure the database user account used by your application only has the permissions it absolutely needs. For example, a web app shouldn't be using a "root" or "admin" account to perform simple searches. 5. Keep Software Updated
Always patch your database management system (DBMS) and any web frameworks you use, as updates often include security fixes for known vulnerabilities.