Does anyone understand Java with MySql?

Discussion in 'Plugin Development' started by Numenorean95, Aug 3, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    Numenorean95

    I first posted this elsewhere, but i figured it might be for noticed here:

    I am building a plugin that uses MySql, but for some reason it gives me this error every time:
    16:28:15 [INFO] BackgroundCheck Enabled
    16:28:16 [INFO] Communications link failure
    The last packet sent successfully to the server was 0 milliseconds ago. The driv
    er has not received any packets from the server.
    16:28:16 [INFO] null (out putting the value)

    My code:
    Code:
    package net.lotrcraft.backgroundcheck;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.Statement;
    public class Connection {
        private static Statement connect(){
            String username = "BackgroundCheck";
            String passwd = "******************";
            try
            {
                Class.forName("com.mysql.jdbc.Driver").newInstance();
                    String dbURL = "jdbc:mysql://lotrcraft.net/database?user="
                    + username + "&password=" + passwd;
                java.sql.Connection myConnection = DriverManager.getConnection(dbURL);
                Statement stat = myConnection.createStatement();
                return stat;
            }
            catch( Exception E ){
                System.out.println( E.getMessage() );
            }
            return null;
        }
        public static int getPlayer(String name){
            Statement stat = connect();
            try
            {
                String selectQuery = "Select * from MyTable WHERE Player = " + name + "/;";
                //get the results
            ResultSet results = stat.executeQuery(selectQuery);
                //output the results
            if (results.equals(null)) return 0;
            return results.getInt("Bans");
            }
            catch( Exception E )
            { BCMain.log.info( E.getMessage() );    }
            return 0;
        }
    }
    //EDIT: Note: the code is a little messed up, ignore the mistakes that dont pertain to the MySql problem
    
    Does anyone know what my error is? the password and user name are correct, of that i am certain.
     
  2. Offline

    Numenorean95

    Where can i find that?
     
  3. In PluginDevelopment > Resources
     
  4. Offline

    Numenorean95

Thread Status:
Not open for further replies.

Share This Page