Opens a connection to a MySQL database @param ip The IP address to connect to @param port The port to connect to @param username The username to log in with @param password The password to log in with @param database The database to use, will be created if it doesn't exist @return The Con
(String ip, int port, String username, String password, String database)
| 51 | * @return The Connection to the MySQL database |
| 52 | */ |
| 53 | public static Connection openMySQL(String ip, int port, String username, String password, String database) { |
| 54 | try { |
| 55 | Class.forName("com.mysql.jdbc.Driver"); |
| 56 | Connection connection = DriverManager.getConnection("jdbc:mysql://" + ip + ":" + port + "/?user=" + username + "&password=" + password); |
| 57 | connection.createStatement().execute("CREATE DATABASE IF NOT EXISTS " + database + ";"); |
| 58 | connection.createStatement().execute("USE " + database + ";"); |
| 59 | return connection; |
| 60 | } catch (ClassNotFoundException | SQLException e) { |
| 61 | sneakyThrow(e); |
| 62 | return null; |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Opens a connection to a MySQL database at localhost:3306 |
nothing calls this directly
no test coverage detected