Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static int host = Main.getPlugin().getConfig().getInt("mysql.host");
- static String database = Main.getPlugin().getConfig().getString("mysql.database");
- static String username = Main.getPlugin().getConfig().getString("mysql.user");
- static String password = Main.getPlugin().getConfig().getString("mysql.pass");
- static int port = Main.getPlugin().getConfig().getInt("mysql.port");
- public static Connection SQLconnect() {
- try {
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- final Connection con = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database,
- username, password);
- return con;
- } catch (final ClassNotFoundException ex) {
- System.err.println("[Training] No MySQL driver found!");
- } catch (final SQLException ex) {
- System.err.println("[Training] Error while fetching MySQL connection!");
- } catch (final Exception ex) {
- System.err.println("[Training] Unknown error while fetchting MySQL connection.");
- }
- return null;
- }
- public static void SQLdisconnect(Connection con) {
- try {
- con.close();
- } catch (SQLException | NullPointerException ex) {
- System.err.println("[Training] Error while closing the connection...");
- }
- }
- public static void createTable() {
- if (!Training.getSql())
- return;
- final Connection con = SQLconnect();
- try {
- final Statement state = con.createStatement();
- state.executeUpdate(
- "CREATE TABLE IF NOT EXISTS accounts(uuid VARCHAR(255),name VARCHAR(16),rank VARCHAR(32),coins INT,level INT,exp INT,played INT,kills INT,deaths INT,kit VARCHAR(255),ks INT)");
- state.executeUpdate(
- "CREATE TABLE IF NOT EXISTS achievements(uuid VARCHAR(255),name VARCHAR(16),kills VARCHAR(5),blocks VARCHAR(5),pickaxe VARCHAR(5))");
- state.executeUpdate(
- "CREATE TABLE IF NOT EXISTS configurations(uuid VARCHAR(255),name VARCHAR(16),anim VARCHAR(5),msg VARCHAR(5),compass VARCHAR(5),title VARCHAR(5))");
- } catch (final SQLException e) {
- System.err.println(e);
- e.printStackTrace();
- }
- SQLdisconnect(con);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement