Library MySQL Connection class

Discussion in 'Resources' started by HungerCraftNL, May 12, 2016.

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


    Hi guys,

    I've made a Connection class a few days ago, and I thought why shouldn't I share it with you guys. It's pritty easy to use if you have some experience with Java and SQL. I'll post a small explaination bellow.


    Making connection
    private Connection con;
    public void onEnable()
      String hostname = "localhost";
      String port = "3306";
      String username = "root";
      String password = "root";
      String database = "database";
      this.con = new Connection(hostname, port, username, password, database);
    public Connection getConnection()
      return this.con;
    Executing select example
    Player p = (Player) sender;
    ArrayList<Object> objs = new ArrayList<Object>();
    ResultSet rs = plugin.getConnection().preparedStatement("SELECT * FROM users WHERE player_uuid=?", objs);
      p.sendMessage("Current balance: " + rs.getDouble("balance"));
    Executing insert example
    Player p = (Player) sender;
    String uuid = p.getUniqueId().toString();
    String item = "blabla";
    plugin.getConnection().updateQuery("INSERT INTO sells (player_uuid, item) VALUES ('"+uuid+"', '"+item+"')");
    Have fun with it, if you have any questions I would love to answer them <3
  2. Offline


    Do you have to put the password in a plain text string?
  3. You can change permissions to only let the user root read from the database and not write
Thread Status:
Not open for further replies.

Share This Page