Connecting to MySQL DB

Discussion in 'Plugin Development' started by MordorKing78, Sep 28, 2016.

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

    MordorKing78

    Hello, so I'm trying to connect to my MySQL database, I just can't seem to figure out how I do it.
    I have no clue what port I put in, if I put in a port the server just stops loading.

    Code:

    Code:
    package org.m.core.main;
    
    import java.sql.Connection;
    import java.sql.SQLException;
    
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Main extends JavaPlugin{
        MySQL MySQL = new MySQL("127.0.0.1", "", "server", "root", ""); //Creating MySQL connection
        Connection c = null;
       
        public void onEnable(){
            try {
                System.out.println("Establishing connection to database..");
                c = MySQL.openConnection();
            } catch (ClassNotFoundException | SQLException e) {
                // TODO Auto-generated catch block
                System.out.println("Connecting to the database has failed!");
                e.printStackTrace();
            }
           
           
            //PluginManager pm = getServer().getPluginManager();
           
            /*
             * TODO: MySQL
             */
        }
    }
    
     
    Last edited: Sep 28, 2016
  2. @MordorKing78
    Instead of just editing out content of threads that you figured out the solution to (I assume this is what happened), keep them and post the solution, it'll be useful for other people having the same issue.
     
  3. Offline

    MordorKing78

    @AlvinB it wasn't quite solved, I just felt like it was a stupid question.
     
  4. Offline

    mythbusterma

    @MordorKing78

    What is "MySQL?' Obtain a connection using the JDBC, that's all you need.
     
  5. Offline

    -_Husky_-

    Also just a heads up, I wouldn't use root for the MySQL user!
    @MordorKing78
     
  6. Offline

    MordorKing78

    @-_Husky_- it's hosted on my pc, doesn't really matter does it? =o
     
  7. Offline

    -_Husky_-

    As long as it's just for a testing server.
     
  8. Offline

    mythbusterma

    @MordorKing78

    Again, use the JDBC. We can't see the connecting code, so we can't help you.
     
  9. Offline

    MordorKing78

    @mythbusterma What exactly is this JDBC you're talking about?
     
  10. Offline

    mythbusterma

    CodePlaysMinecraft likes this.
Thread Status:
Not open for further replies.

Share This Page