Last modified 11 years ago Last modified on 03/14/08 16:25:44

SQL Prepared Statements

In addition to normal queries, relational databases provide a way to bind parameters to certain columns. Here is an example using the Java JDBC API:

PreparedStatement ps = connection.prepareStatement(
    "SELECT email FROM member WHERE name = ?");
ps.setString(1, formField);
ResultSet rs = ps.executeQuery();

Why bother

  • Efficiency: the RDBMS can reuse query plans that have been prepared