← Java / Spring · Contents

JAVA-002 / Beginner

JDBC Statement with string concatenation

A03:2021 Injection · CWE-89 SQL Injection

Why is this a problem?

Authentication can be bypassed with ' OR '1'='1.

How to fix it

java
PreparedStatement ps = conn.prepareStatement("SELECT * FROM users WHERE id = ?");
ps.setString(1, id);

Further reading