Getting Locations from MySql

Discussion in 'Plugin Development' started by dylzqn, Jun 7, 2015.

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

    dylzqn

    How do I get Locations from MySql?

    Errors : return rs.getString();
    return DataBaseError

    Code:
        public static Location getSpawn(String ID, String SpawnNum){
            ResultSet rs = MySql.getResult("SELECT " + SpawnNum + " FROM swSGArenas WHERE ID='" + ID + "'" );
            try {
                if (rs.next()){
                   return rs.getString("SpawnNum");
                }
            }catch (Exception ex){
                ex.printStackTrace();
            }
            return "DataBaseError";
        }
    Thanks :D
     
  2. Offline

    Goblom

    You should have some way of deserializing that string you are getting from the resultset.

    You cannot return a String when the method is expecting a return value of a Location
     
  3. Offline

    mine-care

    @dylzqn Umm how do you store them? when i needed to do this i turned locations to String as so: "World,x,y,z,yaw,pitch" and had a method tor ecover them from String, What is the problem you are facing?
    Also Please do not catch "Exception" catch SQLException instead.
     
  4. Offline

    dylzqn

  5. Offline

    stefvanschie

    @dylzqn Well the first thing I see is that you've stored the world as a world, you probably want to make it a string.
     
  6. Offline

    mythbusterma

    @dylzqn

    A few other notes.

    1. Don't do SQL queries on the main thread of the server, it will cause severe latency issues and may cause the server to hang indefinitely
    2. Don't use static methods for functions that require things that are inherently stateful, like a connection to an SQL server
    3. Don't catch "Exception," it's too broad
    4. Don't use String concatenation to build SQL queries, use PreparedStatements instead.
    5. Why are you using SQL anyway? It doesn't seem something like this would need it.
     
Thread Status:
Not open for further replies.

Share This Page