Program to create a table with Mysql.

Here, we have a basic program example to create table using Mysq in Python and Java.

Code to create table using Mysql in Python

import mysql.connector
con=mysql.connector.connect(host="localhost", user="root", passwd="root", database="coder")
cur=con.cursor()
cur.execute("create table Book( BookName varchar(30), Author varchar(30) )")
con.close()

Code to create table using Mysql in Java

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

public class CreateTable {
   static final String DB_URL = "jdbc:mysql://localhost/TestDb";
   static final String USER = "root";
   static final String PASS = "vsit@123";

   public static void main(String[] args) {
      try(Connection conn = DriverManager.getConnection(DB_URL, USER, PASS);
         Statement stmt = conn.createStatement();
      ) {		      
          String sql = "CREATE TABLE DemoTable " +
                   "(Id INTEGER not NULL, " +
                   " Name VARCHAR(255), " +
                   " CountryName VARCHAR(255), " +
                   " Age INTEGER, " +
                   " PRIMARY KEY ( Id ))";

         stmt.executeUpdate(sql);
         System.out.println("Created table in given database...");   	  
      } catch (SQLException e) {
         e.printStackTrace();
      }
   }
}