Non-DDL-statements can and under all circumstances should be protected against SQL injection. In JDBC this is done with PreparedStatement
and CallableStatement
which allow parameter insertion, but can't be used for DDL statements.
The third is Statement
which allows DDL statements, but doesn't offer parameter insertion. I need to do manual checks of the database name in order to protect against a database name like x"; DROP DATABASE "customer_data
. This manual check feels both like reinventing the wheel and doing security myself which both are bad ideas afaik.
Am I missing a JDBC function? Is creating databases programmatically evil? Do stored procedures provide an additional level of protection? Are there well maintained and audited libraries for checking database names and similar variables passed to DDL statements.