Create Table using Statement in Java

Statements in JDBC are used to execute SQL statements that do not require dynamic parameters passed to the query. Lets see how to create create table using statement in java.

Please note : We will be using MYSql database for executing the SQL statement.
If you are using any other database , then for executing the sample code change the getConnection() to connect to your database.

We will use the Statement.execute(String sql) method to execute the create table sql.

Create Table SQL

Below is the query that can be fired directly on database to create table

Now lets see the sample code for firing this SQL using JDBC

Example : Create Table using Statement in Java


Since we have JDK 7, we are using Try-with-resources Statement to handle the resources that are opened.


1. Statement Java