How to create a MySQL DB in Java?

  • 0
    Kind
    I want the application to check for the presence of a database when it starts up, and in case of absence, a script to create a database (namely a database, not tables in the created database) in MySQL is executed.
    so I connect to the database
    private static final String test = "jdbc:mysql://localhost:3306?useUnicode=true&useSSL=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC&create=true";

    then I send the script
    try {
                Statement statementTest = ConnectionDB.getInstance().getConnectionTest().prepareCall("create database test;");
            } catch (SQLException e) {
                e.printStackTrace();
            }

    but nothing happens, no errors are reported
    Java Anonymous, Mar 6, 2019

  • 2 Answers
  • 0
    I may be wrong, but most likely in the first script you do not connect to the database, but just assign the `test` variable the value of the address where the connection is made. Then, in theory, you should use it as an argument in the `getConnection` method
    Anonymous

  • 0
    I figured it out myself, the solution here if anyone needs it
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!