N
N
Neonoviiwolf2016-10-23 14:05:43
MySQL
Neonoviiwolf, 2016-10-23 14:05:43

How to create a MySQL DB in Java?

I
want the application to check the presence of a database at startup and, in case of absence, a script is executed to create a database (namely, a database, not tables in the created database) in MySQL.
so I connect to the db

private static final String test = "jdbc:mysql://localhost:3306?useUnicode=true&useSSL=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC&create=true";

then 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

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Oleg, 2016-10-23
@ptrvch

I may be wrong, but most likely in the first script you are not connecting to the database, but simply assigning the value of the address to which the connection is made to the `test` variable. Further, in theory, you should use it as an argument in the `getConnection` method

N
Neonoviiwolf, 2016-10-23
@Neonoviiwolf

Everything, I figured it out myself, the solution is here , if anyone needs it

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question