Create a Database Table using JDBC PreparedStatement


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;


public class JDBCCreateTableExample {
    
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
    
        String url ="jdbc:mysql://localhost:3306/my_uat";
        String userName="root";
        String password ="root123";
        String createTableQuery ="create table my_table (id int NOT NULL, data varchar(500));";
        Connection connection = DriverManager.getConnection(url,userName,password);
        PreparedStatement preparedStatement = connection.prepareStatement(createTableQuery);
    
        preparedStatement.execute();
        System.out.println("Table created..");
    
    }
}
Output: Table created..
Create Database table using Java JDBC
Create Database table using Java JDBC
-


Have Questions? Post them here!

Top Hashtags:

Advertisements

Advertisements




Advertisements