JDBC PS DDL statements with executeUpdate

How to do SQL DDL Statements with the
executeUpdate() method existing in the PreparedStatement Object?

With a DB connection, you must write the SQL DDL statement
and let this statement
be the parameter to the below specified prepareStatement() method.

If you have any parameter in your SQL statement, then it is time to
set these using the PreparedStatment
setXXX() methods.

Now you can create a PreparedStatment object with the method:

Method in Connection interface

Description

PreparedStatement prepareStatement(String sql)

Creates a PreparedStatement
object for sending parameterized SQL statements to the database.

With the returned PreparedStatement object, you can execute the following
method to perform the SQL DDL statement:

Method in PreparedStatement interface

Description

int executeUpdate()

Executes the SQL statement in this
PreparedStatement object, which must be an SQL Data Manipulation
Language (DML) statement, such as INSERT, UPDATE or DELETE;
or an SQL statement that returns nothing, such as a DDL statement.

Example of using this executeUpdate() and a PreparedStatement object
to do SQL DDL statement: