As you are creating a database from scratch, you could use:
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost/?user=root&password=rootpassword"); PreparedStatement ps = connection.prepareStatement("CREATE DATABASE databasename"); int result = ps.executeUpdate();
Here is an identical scenario.
Related Posts:
- Getting java.sql.SQLException: Operation not allowed after ResultSet closed
- com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
- com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
- java.sql.SQLException: No database selected – why?
- SQL Error: 0, SQLState: 08S01 Communications link failure
- Cannot issue data manipulation statements with executeQuery()
- How to grant remote access permissions to mysql server for user?
- Connection Java – MySQL : Public Key Retrieval is not allowed
- MySQL Error: : ‘Access denied for user ‘root’@’localhost’
- MySQL Error: : ‘Access denied for user ‘root’@’localhost’
- What is a StackOverflowError?
- How to use mysqli_query() in PHP?
- Access Denied for User ‘root’@’localhost’ (using password: YES) – No Privileges?
- What is the proper way to handle a NumberFormatException when it is expected?
- Exception in thread “main” java.util.NoSuchElementException
- How can I solve “java.lang.NoClassDefFoundError”?
- Access Denied for User ‘root’@’localhost’ (using password: YES) – No Privileges?
- ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: YES)
- Column count doesn’t match value count at row 1
- java.lang.ClassNotFoundException: com.mysql.jdbc.Driver in Eclipse
- ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: YES)
- MySQL string replace
- Cannot add or update a child row: a foreign key constraint fails
- java.lang.ClassNotFoundException: com.mysql.jdbc.Driver in Eclipse
- ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: YES)
- String concatenation in MySQL
- What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it?
- What’s the difference between INNER JOIN, LEFT JOIN, RIGHT JOIN and FULL JOIN? [duplicate]
- Cannot add or update a child row: a foreign key constraint fails
- MySQL Error “Operand should contain 1 column”
- getting error HTTP Status 405 – HTTP method GET is not supported by this URL but not used `get` ever?
- How to use MySQL DECIMAL?
- Access denied for user ‘root@localhost’ (using password:NO)
- Can’t connect to local MySQL server through socket ‘/var/mysql/mysql.sock’ (38)
- How to make MySQL table primary key auto increment with some prefix
- Access denied for user ‘root@localhost’ (using password:NO)
- MySQL ERROR 1290 (HY000) –secure-file-priv option
- What could cause java.lang.reflect.InvocationTargetException?
- JavaFX – Exception in Application start method?
- MySQL error 2006: mysql server has gone away
- Which MySQL data type to use for storing boolean values
- JavaFX – Exception in Application start method? [duplicate]
- sql query with multiple where statements
- ERROR 2003 (HY000): Can’t connect to MySQL server on localhost (10061)
- ERROR 1698 (28000): Access denied for user ‘root’@’localhost’
- Why would a “java.net.ConnectException: Connection timed out” exception occur when URL is up?
- Cannot delete or update a parent row: a foreign key constraint fails
- Cannot delete or update a parent row: a foreign key constraint fails
- ERROR 2003 (HY000): Can’t connect to MySQL server on localhost (10061)
- MySQL server startup error ‘The server quit without updating PID file’
- Rename a column in MySQL
- Given final block not properly padded
- Can’t find mysqladmin on Mac OSX 10.6.8
- What is an AssertionError? In which case should I throw it from my own code?
- DB2 jdbc connection error Connection refused. ERRORCODE=-4499, SQLSTATE=08001
- “INSERT IGNORE” vs “INSERT … ON DUPLICATE KEY UPDATE”
- Cannot delete or update a parent row: a foreign key constraint fails
- EOFException – how to handle?
- A JNI error has occurred, please check your installation and try again in Eclipse x86 Windows 8.1
- MySQL server startup error ‘The server quit without updating PID file’
- How do I restore a dump file from mysqldump?
- Syntax error due to using a reserved word as a table or column name in MySQL
- ERROR 1698 (28000): Access denied for user ‘root’@’localhost’
- MySQL root password change
- Why would a “java.net.ConnectException: Connection timed out” exception occur when URL is up?
- Installation of MySQL for Visual Studio 1.2.8 failed
- Not unique table/alias
- How do I import an SQL file using the command line in MySQL?
- PHP Connection failed: SQLSTATE[HY000] [2002] Connection refused
- #1273 – Unknown collation: ‘utf8mb4_unicode_520_ci’
- MySQL ERROR 1045 (28000): Access denied for user ‘bill’@’localhost’ (using password: YES)
- Your password does not satisfy the current policy requirements
- Can I catch multiple Java exceptions in the same catch clause?
- How do I quickly rename a MySQL database (change schema name)?
- What does SQL Select symbol || mean?
- Install mysql-python (Windows)
- MySQL: Access denied for user ‘test’@’localhost’ (using password: YES) except root user
- PHP Connection failed: SQLSTATE[HY000] [2002] Connection refused
- Exception in thread “main” java.util.NoSuchElementException: No line found
- SQL – Update multiple records in one query
- java.net.MalformedURLException: no protocol
- Mysql: Setup the format of DATETIME to ‘DD-MM-YYYY HH:MM:SS’ when creating a table
- What is the definition of cardinality in SQL
- “NoClassDefFoundError: Could not initialize class” error
- How to restart remote MySQL server running on Ubuntu linux?
- Authentication plugin ‘caching_sha2_password’ cannot be loaded
- MySQL DROP all tables, ignoring foreign keys
- unreported exception java.io.FileNotFoundException; must be caught or declared to be thrown
- #1055 – Expression of SELECT list is not in GROUP BY clause and contains nonaggregated column this is incompatible with sql_mode=only_full_group_by
- When to use SELECT … FOR UPDATE?
- Host ‘xxx.xx.xxx.xxx’ is not allowed to connect to this MySQL server
- Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
- Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)
- Setting up foreign keys in phpMyAdmin?
- Select from multiple tables without a join?
- PHP Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP
- ERROR 1396 (HY000): Operation CREATE USER failed for ‘jack’@’localhost’
- SQL Query Where Field DOES NOT Contain $x
- Create a new database with MySQL Workbench
- Exception in thread “main” java.lang.UnsupportedClassVersionError: a (Unsupported major.minor version 51.0)