The Statement object, as I understand, is not to be used in developing Enterprise applications as it has all sorts of issues in a good application. Why has it not been deprecated yet in newer versions?
Statement
is a perfectly fine interface. What's bad is creating queries by concatenating strings together, especially strings containing user input. If you're only issuing constant queries containing no variables, the simple Statement
interface serves perfectly well.
Statement
Use for general-purpose access to your database. Useful when you are using static SQL statements at runtime. The Statement interface cannot accept parameters.
The use of a Statement in JDBC should be 100% localized to being used for DDL (ALTER, CREATE, GRANT, etc) as these are the only statement types that cannot accept BIND VARIABLES.
PreparedStatement
Use when you plan to use the SQL statements many times. The PreparedStatement interface accepts input parameters at runtime.
PreparedStatements or CallableStatements should be used for EVERY OTHER type of statement (DML, Queries). As these are the statement types that accept bind variables.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With