- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Create a database in MySQL from Java?
The following is the code to create a database in MySQL from Java. We are creating the database with name, “Customer_Tracker_Database”
import java.sql.Connection; import java.sql.DriverManager; import java.sql.Statement; public class CreateDatabaseDemo { public static void main(String[] args) { Connection con=null; Statement stmt=null; String yourDatabaseName="Customer_Tracker_Database"; try { con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test3?useSSL=false", "root","123456"); stmt = con.createStatement(); int status = stmt.executeUpdate("CREATE DATABASE "+yourDatabaseName); if(status > 0) { System.out.println("Database is created successfully !!!"); } } catch(Exception e) { e.printStackTrace(); } } }
The following is the output
Database is created successfully !!!
Here is the snapshot of the sample output
Now let us check the database ‘Customer_Tracker_Database’ is created or not.
The query is as follows
mysql> show databases;
The following is the output
Look at the sample output above, the database is created successfully.
- Related Articles
- Retrieving MySQL Database structure information from Java?
- Create a new database with MySQL Workbench?
- How can we create a table from an existing MySQL table in the database?
- Get the last record from a table in MySQL database with Java?
- How to create a database in MongoDB using Java?
- How to create a database on command line in MySQL?
- How to create a database in MySQL using a JDBC API?
- Connecting to a MySQL database with Java
- Can we create a database with a numeric name with MySQL?
- Get a list of Constraints from MySQL Database?
- How to retrieve table names from a database in MySQL?
- How to update data in a MySQL database with Java?
- How to delete data in a MySQL database with Java?
- Selecting random entry from MySQL Database?
- How can we create user accounts in MySQL database server?

Advertisements