Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void connect() {
- try {
- this.connection = DriverManager.getConnection("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database + "?autoReconnect=true", this.user, this.password);
- this.update("CREATE TABLE IF NOT EXISTS Clans (Name VARCHAR(16),Tag VARCHAR(4),Members TEXT, Owners TEXT, Invites TEXT)");
- this.update("CREATE TABLE IF NOT EXISTS FriendSystem (UUID VARCHAR(64),Name VARCHAR(16),Friends TEXT,Invites TEXT,Online INT(100),Notify INT(100),Message INT(100),Jump INT(100),Request INT(100))");
- this.update("CREATE TABLE IF NOT EXISTS Groups (Name TEXT,Displayname TEXT,Tabprefix TEXT,Chatprefix TEXT,Rankcolor TEXT,SortID INT, TeamSpeakID INT, Permissions TEXT)");
- this.update("CREATE TABLE IF NOT EXISTS Users (UUID VARCHAR(64), Name VARCHAR(16), Gruppe VARCHAR(100), Notify VARCHAR(100), FirstLogin VARCHAR(100), LastLogin VARCHAR(100), IP VARCHAR(100), NickName VARCHAR(100))");
- this.update("CREATE TABLE IF NOT EXISTS TeamSpeak (UUID VARCHAR(64), UID VARCHAR(64), RankID INT(5))");
- this.update("CREATE TABLE IF NOT EXISTS BanSystem (UUID VARCHAR(64),Map TEXT)");
- this.update("CREATE TABLE IF NOT EXISTS BanSystemTemplates (Name TEXT,Time TEXT)");
- this.update("CREATE TABLE IF NOT EXISTS MuteSystem (UUID VARCHAR(64),Map TEXT)");
- this.update("CREATE TABLE IF NOT EXISTS MuteSystemTemplates (Name TEXT ,Time TEXT)");
- this.update("CREATE TABLE IF NOT EXISTS ChatFilter (Map TEXT)");
- this.update("CREATE TABLE IF NOT EXISTS ReportSystem (UUID VARCHAR(64), Map TEXT)");
- this.update("CREATE TABLE IF NOT EXISTS ClanSystem (Name VARCHAR(16), Tag VARCHAR(5), Leader TEXT, Member TEXT, Invites TEXT)");
- ResultSet rs = this.asyncQuery("SELECT * FROM ChatFilter");
- if (!rs.next()) {
- this.update("INSERT INTO ChatFilter (Map) VALUES ('" + new Gson().toJson(new ArrayList()) + "')");
- }
- }
- catch (SQLException e) {
- this.connection = null;
- e.printStackTrace();
- }
- }
- public void disconnect() {
- try {
- this.connection.close();
- this.connection = null;
- }
- catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public void update(String qry) {
- try {
- Throwable throwable = null;
- Object var3_5 = null;
- try {
- PreparedStatement preparedStatement = this.connection.prepareStatement(qry);
- try {
- preparedStatement.executeUpdate();
- }
- finally {
- if (preparedStatement != null) {
- preparedStatement.close();
- }
- }
- }
- catch (Throwable throwable2) {
- if (throwable == null) {
- throwable = throwable2;
- } else if (throwable != throwable2) {
- throwable.addSuppressed(throwable2);
- }
- throw throwable2;
- }
- }
- catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public void asyncUpdate(final String qry) {
- EXECUTOR_SERVICE.execute(new Runnable(){
- @Override
- public void run() {
- MySQL.this.update(qry);
- }
- });
- }
- public ResultSet query(String qry) {
- try {
- return this.connection.prepareStatement(qry).executeQuery();
- }
- catch (SQLException e) {
- e.printStackTrace();
- return null;
- }
- }
- public ResultSet asyncQuery(final String qry) {
- Future future = EXECUTOR_SERVICE.submit(new Callable<ResultSet>(){
- @Override
- public ResultSet call() throws Exception {
- return MySQL.this.query(qry);
- }
- });
- try {
- return (ResultSet)future.get();
- }
- catch (Exception e) {
- e.printStackTrace();
- return null;
- }
- }
- public static MySQL getInstance() {
- return instance;
- }
- public boolean isConnected() {
- if (this.connection != null) {
- return true;
- }
- return false;
- }
- }
Add Comment
Please, Sign In to add comment