MySQL issue

Discussion in 'Spigot Plugin Development' started by metmad22, Jun 13, 2015.

  1. Hello community, I have spent hours trying to figure out a way to bypass this issue, but I can not find any. I appreciate all your help. Here is the issue.

    I made a plugin that saves player information from a server to the MySQL database. However, all this saved information passes through a VPN connection before reaching the desired server. Now the issue is, once in a while the VPN gets disconnected. Once the information can no longer reach the MySQL database, the whole minecraft server crashes and times out. I tried making this code to check if there is a connection or not, but it doesn't seem to be working every time and it really is unpredictable.

    Code (Text):
        public boolean checkConnection() throws SQLException
        {
            return (c != null && !c.isClosed()) ? true : false;
            //PS: The variable 'c' is the connection to the MySQL database
        }

        /**
         * FUNCTION -> queryDbThreaded();
         * * *
         * ALIAS FOR FUNCTION mysqlMethod(), USED FOR OPENING A NEW THREAD.
         */
        public void queryDbThreaded(final Player player, final String text, final Integer type, final String xyz)
        {
            try
            {
                if (checkConnection() == true)
                {
                    Bukkit.getScheduler().runTaskAsynchronously(this, new Runnable() {
                        @Override
                        public void run() {
                            mysqlMethod(player, text, type, xyz);
                        }
                    });
                }
                else
                {
                    //TODO: WRITE DATA TO A SERIALIZED .DATA FILE
                    if ( reconnectDB() )  { getLogger().info("The DB was down, but now it's back up!"); }
                    else { getLogger().info("The DB Seems DOWN!! Waiting.."); }

                }
            }
            catch (Exception e)
            {
                errorHandler(e);
            }
        }
    I need to check if the VPN/connection on the target server is down or not. If it's up and running, continue sending the information to the MySQL database. If it's down, write it to a file basically.

    Thanks!
     
    #1 metmad22, Jun 13, 2015
    Last edited: Jun 13, 2015
  2. Why are you using a VPN in the first place o_O?
     
  3. Good question. It's against my will and I am running my code though a friend's private server. And he hosts it with his VPN. That's the issue I'm trying to fix. Is there any way you can allow certain packets to reach a server without passing through a VPN?