MCPcopy Create free account
hub / github.com/boxbeam/RedLib / openMySQL

Method openMySQL

src/redempt/redlib/sql/SQLHelper.java:53–64  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 3

sneakyThrowMethod · 0.95
getConnectionMethod · 0.80
executeMethod · 0.80

Tested by

no test coverage detected