Can MySQL Databases Be Created from Java?
While typical examples of connecting to MySQL databases through Java include a database name in the connection URL, it is also possible to create a database without one. This can be useful when only a login name and password are available.
Creating a Database with Limited Credentials
To create a MySQL database in Java with only a login name and password, follow these steps:
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/?user=root&password=rootpassword");
Statement stmt = conn.createStatement();
int result = stmt.executeUpdate("CREATE DATABASE databasename");
By following these steps, you can successfully create a MySQL database from Java using only login credentials.
The above is the detailed content of Can Java Create MySQL Databases Using Only Login Credentials?. For more information, please follow other related articles on the PHP Chinese website!