JDBC, or Java DataBase Connectivity, is the Java specification for connecting to (relational) databases. JDBC provides a common API in the form of a number of interfaces and exceptions, and expectations (or requirements) of drivers.
The JDBC specification consists of two parts:
java.sql
and javax.sql
)Most relational databases, and some non-relational databases, provide a driver that implements the JDBC.
A PreparedStatement
declares the statement before it is executed, and allows for placeholders for parameters. This allows the statement to be prepared (and optimized) once on the server, and then reused with different sets of parameters.
The added benefit of the parameter placeholders, is that it provides protection against SQL injection. This is achieved either by sending the parameter values separately, or because the driver escapes values correctly as needed.
Statement batching allows a program to collect related statement, or in the case of prepared statements related parameter value sets, and send them to the database server as a single execute.
The benefits of statement batching can include improved performance. If and how these performance benefits are achieved depends on the driver and database support, but they include: