Java Project JSP JDBC Java Program Core Java Demo MORE

How to Create table in MySql using JSP code

A database consists of one or more tables.

The CREATE DATABASE statement is used to create a database in MySQL.

The following examples create a database named "test":


<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
<%@ page import="java.sql.*" %>

        <title>Create a Database using JSP</title>

        <h1>Create a Database using JSP</h1>

            Connection connection = null;
            try {
                connection = DriverManager.getConnection("jdbc:mysql://localhost:3306", "root", "");

                Statement statement = connection.createStatement();
                String query = "CREATE DATABASE test";
                out.println("Database test created sucessfully.");
            catch (Exception e) 
                out.println("An error occurred.");