Connecting to a database with MySQL -FML

Discussion in 'Plugin Development' started by SjamonDaal, Feb 1, 2016.

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

    SjamonDaal

    Hello everyone!

    I am trying to connect a plugin with my MySQL Database but i can't get the code fixed at this point.

    Is there anyone with a lot of experience over here?

    Please don't send a link or word i need to follow
    If you try to help me you will help me by telling me what i need to change to what.

    I followed this tutorial


    and this page:
    https://bukkit.org/threads/using-mysql-in-your-plugins.132309/


    This is my code:
    Code:
    package me.SjamonDaal.sh;
    
    import java.sql.SQLException;
    import java.sql.Statement;
    
    import com.huskehhh.mysql.mysql.MySQL;
    
    public class MySQLManager {
    
        private final Superheat main;
        private MySQL db;
    
        public MySQLManager(Superheat h) {
            this.main = h;
        }
    
        public void setupDB() throws SQLException {
            this.db = new MySQL("localhost", "3306", "database", "username", "password");
            this.db.openConnection();
            Statement statement = this.db.getConnection().createStatement();
            statement.executeUpdate("CREATE TABLE IF NOT EXISTS `superheatlog` (`Name` varchar(32),`User` int)");
            statement.close();
        }
      
        public void closeDB() {
            this.db.closeConnection();
        }
    
    }
    
    Result:
    [​IMG]


    In the video tutorial he tells that i need to do it like this:
    Code:
    public void setupDB() throws SQLException {
            this.db = new MySQL(this.main, "localhost", "3306", "database", "username", "password");
            this.db.openConnection();
            Statement statement = this.db.getConnection().createStatement();
            statement.executeUpdate("CREATE TABLE IF NOT EXISTS `superheatlog` (`Name` varchar(32),`User` int)");
            statement.close();
        }
    but then i get this as result:
    [​IMG]


    Does anyone have any idea how i can fix this?

    Kind Regards,
    D. Staal

    UPDATE:
    I did do this,
    [​IMG]

    If it's stupid please comment!!!!
     
    Last edited: Feb 1, 2016
  2. Offline

    JTGaming2012

    What's the actual error? What does it say when you hover over the red line?
     
  3. Offline

    mythbusterma

    @SjamonDaal

    Just stop using anyone else's code for this. It's a waste of time and frankly counter-productive. Write the code for this yourself, simply follow Oracle's tutorial on using the JDBC for MySQL. It will show you how to properly write the code for this.

    http://dev.mysql.com/doc/connector-j/en/
     
  4. Offline

    SjamonDaal

    Thanks for your comment,

    Well I don't think it's a wast of time.
    I am just a starter at Java and I don't know thay much so we Will try this but i don't think we Will find ot out.

    Regards,
    D. Staal
     
Thread Status:
Not open for further replies.

Share This Page