Main Content

SQL Prepared Statements

Create and execute SQL prepared statements

An SQL prepared statement consists of a single SELECT, INSERT, UPDATE, DELETE, or CALL SQL statement and has parameters that are bound to specified values.

Use the SQLPreparedStatement object to create an SQL prepared statement. Then, you can import, insert, update, or delete data in the database. Also, you can call stored procedures. You import data using the fetch function. For other database operations, you use the execute function.

An SQL prepared statement enables you to improve performance by executing one SQL statement with different values instead of creating multiple SQL statements. Also, an SQL prepared statement improves security by binding specified values to parameters.

You can use SQL prepared statements with a JDBC database connection only.


SQLPreparedStatementSQL prepared statement (Since R2019b)


expand all

databasePreparedStatementCreate SQL prepared statement (Since R2019b)
bindParamValuesBind values to parameters (Since R2019b)
closeClose SQL prepared statement (Since R2019b)
executeExecute SQL statement using relational database connection
fetchImport data into MATLAB workspace from execution of SQL statement