以下是从Java在MySQL中创建数据库的代码。我们正在创建名称为“ 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(); } } }
以下是输出
Database is created successfully !!!
这是示例输出的快照
现在,让我们检查数据库“ Customer_Tracker_Database”是否已创建。
查询如下
show databases;
以下是输出
Look at the sample output above, the database is created successfully.