Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package de.proxysocke.net.joey.joeyvotesystem.Database;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.SQLException;
- import java.text.MessageFormat;
- import java.util.concurrent.ExecutorService;
- import java.util.concurrent.Executors;
- public class MySQLManager {
- public static String host = "localhost";
- public static String port = "3306";
- public static String database = "devserver";
- public static String username = "devserver";
- public static String password = "EvcJJlrBNf0JF251";
- public static Connection con;
- private static ExecutorService mservice = Executors.newCachedThreadPool();
- public static void connect(){
- if(isConnectet() == false){
- try {
- String url = MessageFormat.format("jdbc:mysql://{0}:{1}/{2}", host, port, database);
- con = DriverManager.getConnection(url, username, password);
- System.out.println("[JoeyMySQLManager @JoeyVoteSystem] Verbindung wurde hergestellt");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static void checkConnection(){
- if(!isConnectet()){
- connect();
- }
- }
- public static void disconect(){
- if(isConnectet() == true){
- try {
- con.close();
- System.out.println("[JoeyMySQLManager @JoeyVoteSystem] Verbindung wurde getrennt");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static void UpdateAsync(final PreparedStatement statement){
- mservice.execute(()-> {
- try {
- update(statement);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- });
- }
- private static void update(PreparedStatement statement) throws SQLException{
- if(isConnectet() == true){
- statement.executeUpdate();
- statement.close();
- }
- }
- private static boolean isConnectet(){
- if(con == null){
- return false;
- } else {
- return true;
- }
- }
- public static Connection getConnection(){
- return con;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement