Home >Database >Mysql Tutorial >How to Create a MySQL Database from Java Without Specifying the Database Name in the JDBC URL?
It's possible to create a MySQL database from Java even when the database name is not specified in the JDBC URL. Here's how to do it:
String url = "jdbc:mysql://localhost:3306/?user=root&password=rootpassword"; Connection con = DriverManager.getConnection(url);
Statement s = con.createStatement();
int result = s.executeUpdate("CREATE DATABASE databasename");
s.close(); con.close();
By following these steps, you can create a MySQL database in Java even without specifying the database name in the JDBC URL.
The above is the detailed content of How to Create a MySQL Database from Java Without Specifying the Database Name in the JDBC URL?. For more information, please follow other related articles on the PHP Chinese website!