JDBC PreparedStatement Example – Insert record

290 Flares Twitter 0 Facebook 0 Google+ 290 LinkedIn 0 Filament.io 290 Flares ×

Why PreparedStatement

PreparedStatement offers the advantages of  Pre Compiled SQL.  When you create a PreparedStatement, you have to supply an SQL query to it where as you can just create a Statement object without any query. This means when a  PreparedStatement is created, it is send to the DBMS straightaway where it gets compiled. This means the PreparedStatement object actually holds a pre-compiled SQL. When you execute, the DBMS can directly execute the SQL without the need to compile as it was already compiled.

Typically PreparedStatement objects are used with queries with parameters.The advantage of using SQL statements that take parameters is that you can use the same statement and supply it with different values each time you execute it.

PreparedStatement – Example