About MySQL

Discussion in 'Spigot Plugin Development' started by CodingPig, Jun 16, 2016.

  1. Ok so i'm looking for all the MySQL API and my friend give me a class
    Code (Text):
    static final String DB_NAME = "jdbc:mysql://localhost:3306/mcfs";
        static final String USER = "root";
        static final String PASS = "[email protected]**";
        Connection conn;
        Statement s;
        private ItemStack item = null;

        public void giveItem(final Player p) {
            final Plugin pl = this;
            getServer().getScheduler().runTaskAsynchronously(this, new Runnable() {
                public void run() {
                    try {
                        ResultSet check = s.executeQuery(
                                "SELECT * FROM fb_share_log WHERE name = \"" + p.getName() + "\" AND received=0");
                        if (check.next()) {
                                s.execute("UPDATE fb_share_log SET received=1 WHERE name = \"" + p.getName() + "\"");
                            Bukkit.getScheduler().runTask(pl, new Runnable() {
                                public void run() {
                                    if (p.getInventory().firstEmpty() == -1)
                                                "§cRương bạn đã đầy không thể nhận quà điểm danh, hãy dọn dẹp rương rồi thử lại.");
                                    else {
                                        p.sendMessage("§aBạn vừa nhận được vật phẩm " + item.getItemMeta().getDisplayName()
                                                + "§a, chúc bạn chơi game vui vẻ.");

                        } else {
                            p.sendMessage("§cHôm nay bạn chưa chia sẻ trên Facebook hoặc đã nhận quà rồi.");
                            p.sendMessage("§cTruy cập §ehttp://minefs.net §crồi bấm nút chia sẻ để nhận quà.");
                    } catch (SQLException e) {

        public void onEnable() {
            getServer().getPluginManager().registerEvents(this, this);
            item = this.getConfig().getItemStack("itemtogive");
            try {
                getLogger().info("About to connect to database");
                conn = (Connection) DriverManager.getConnection(DB_NAME, USER, PASS);
                getLogger().info("Successfully connected.");
                getLogger().info("About to create a statement");
                s = (Statement) conn.createStatement();
                getLogger().info("Successfully created statement.");
            } catch (Exception ex) {
    The API and the class which my friend give me have this kind of code
    s.execute("UPDATE fb_share_log SET received=1 WHERE name = \"" + p.getName() + "\"");
    I know it is some type of mysql command but can you guys explain to me how it work and here're some more question
    + Like in config file, i want to register a player with a number with it (getConfig().set("Data."+player.getName());) but how to use the execute method and stuff (i don't want to make it more complex i'm newb to mysql :) )
    + And also get the value too, like getConfig().getInteger("Data."+player.getName());
    + Changing the data value and remove the data value
    If there's tutorial about this send me thanks for reading
  2. I'm not sure, but is this what you are looking for? http://alvinalexander.com/java/java-mysql-select-query-example
    • Useful Useful x 1
  3. Glad I could help!
    • Like Like x 1