[SOLVED] How to connect to MySQL (JDBC Connector) ?

Discussion in 'Plugin Development' started by LiqouRiiCe__, May 2, 2012.

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

    LiqouRiiCe__

    I am having VERY big trubles with JDBC Connector, I'm quite decent in Java programming but I never had to use MySQL before. I'm reading forums and watching tutorials for two solid hours now.

    I tried: Editing Manitest file after exporting (Winrar), editing .classpath, placing/renaming connnector in main bukkit folder/lib/bin/plugin's with no luck.

    In eclipse I have added JDBC MySQL Driver LIBRARY (also tried as external jar).

    This is the code (part of onEnable):
    Code:
     String host = getConfig().getString("server.host");
    String port = getConfig().getString("server.port");
    String user = getConfig().getString("server.username");
    String pass = getConfig().getString("server.password");
    String db = getConfig().getString("server.database");
    try {
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    con = DriverManager.getConnection("jdbc:mysql//" + host + ":" + port + "/" + db, user, pass);
    log.info("[AholaBan] Connected to MySQL database.");
    } catch (SQLException e) {
    e.printStackTrace();
    } catch (ClassNotFoundException e) {
    e.printStackTrace();
    } catch (InstantiationException e) {
    e.printStackTrace();
    } catch (IllegalAccessException e) {
    e.printStackTrace();
    }

    Stack Trace:
    Code:
    23:16:01 [SEVERE] java.sql.SQLException: No suitable driver found for jdbc:mysql//localhost:3306/min
    ecraft
    23:16:01 [SEVERE]      at java.sql.DriverManager.getConnection(Unknown Source)
    23:16:01 [SEVERE]      at java.sql.DriverManager.getConnection(Unknown Source)
    23:16:01 [SEVERE]      at com.aholacraft.aholaban.AholaBan.onEnable(AholaBan.java:47)
    23:16:01 [SEVERE]      at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:215)
    23:16:01 [SEVERE]      at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.jav
    a:336)
    23:16:01 [SEVERE]      at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.ja
    va:381)
    23:16:01 [SEVERE]      at org.bukkit.craftbukkit.CraftServer.loadPlugin(CraftServer.java:250)
    23:16:01 [SEVERE]      at org.bukkit.craftbukkit.CraftServer.enablePlugins(CraftServer.java:232)
    23:16:01 [SEVERE]      at org.bukkit.craftbukkit.CraftServer.reload(CraftServer.java:543)
    23:16:01 [SEVERE]      at org.bukkit.Bukkit.reload(Bukkit.java:182)
    23:16:01 [SEVERE]      at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:22)
    23:16:01 [SEVERE]      at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:166)
    23:16:01 [SEVERE]      at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:473)
    23:16:01 [SEVERE]      at org.bukkit.craftbukkit.CraftServer.dispatchServerCommand(CraftServer.java
    :469)
    23:16:01 [SEVERE]      at net.minecraft.server.MinecraftServer.b(MinecraftServer.java:596)
    23:16:01 [SEVERE]      at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:565)
    23:16:01 [SEVERE]      at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:449)
    23:16:01 [SEVERE]      at net.minecraft.server.ThreadServerApplication.run(SourceFile:492)
    In-depth info/tutorial would be appreciated :) If I do it, I know how it's done and how it works, not just "It works, whatever".
    It's frustrating me.
     
  2. Offline

    stelar7

    LiqouRiiCe__ likes this.
  3. Offline

    LiqouRiiCe__

    Well, I'm not having problems with MySQL it self, but using the connector to connect. I could use some info like: How you add connector to the project (external jar/library), any modifications to classpath, FINAL location of the connector when using plugin on the server.
    As it has problem finding it.

    Something like small tutorial, for the boring stuff ;)
    Thanks :)

    Is it really so hard ? :(

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 25, 2016
  4. Offline

    stelar7

    if you are making a bukkit plugin, then the connector is included in craftbukkit.jar
    if not, put the connector in the same folder as the .jar and it should work
     
    LiqouRiiCe__ likes this.
  5. Offline

    LiqouRiiCe__

    Thanks, but what should it be named ? mysql-connector-java-bin.jar doesnt work. I may just ask some dev. who have a plugin which includes MySQL in plugin. Thanks again ;) If someone has any info, you can still post it :)
     
  6. Offline

    stelar7

    the name of the file does not matter, afaik
     
    LiqouRiiCe__ likes this.
  7. Offline

    ItsHarry

    I don't think you actually need the connector to be in the project
     
    LiqouRiiCe__ likes this.
  8. Offline

    LiqouRiiCe__

    Okay, so does this indicate the problem with my code ? Or something with CB ? I use normal CraftBukkit rather then Bukkit which is for development (only ?) ?!

    Edit: I think I've missed that extends Database

    extends Database doesn't even work when importing library >.<

    stelar7 Could you please tell me what's imported into your project as external JAR/library/everything ?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 25, 2016
  9. Offline

    stelar7

    I import the entire .jar of the files on github (LINK TO JAR) and thats it

    usage example here
     
    LiqouRiiCe__ likes this.
  10. Offline

    ItsHarry

    Well it might be a different problem as the OP suggested.

    It says that the driver couldn't be found, maybe you don't have the SQL driver on your computer?
    Make sure you have MySQL Server 5.0 or something installed so that it will actually work, also make sure the service is enabled and that you have the password of your db and stuff right :)
     
    LiqouRiiCe__ likes this.
  11. Offline

    LiqouRiiCe__

    stelar7
    ItsHarry

    I'd like to thank you very much, both of you. Thanks for your time, I appreciate everything.

    stelar7 I went with MAPI, I'm rewriting my code now for MAPI to use and I will test in than. Thanks ;)
    ItsHarry I'm sure I enabled it and have XAMPP installed, but the things just didn't go right, I hope MAPI will work now ;)


    Thank you again ;)
    I will report back when I finish the MySQL thing if it works or not (under new bukkit dev account: lololmaker).
     
  12. Offline

    ItsHarry

    Alright, good luck :)
     
  13. Offline

    lololmaker

    This is my new account now. Someone could already make comic about me -_-

    Day 4: Still full of errors

    Code:
    18:10:09 [SEVERE] Error occurred while enabling AholaBan v0.9 (Is it up to date?)
    java.lang.NoClassDefFoundError: MAPI/Databases/MySQL
            at com.aholacraft.aholaban.AholaBan.onEnable(AholaBan.java:43)
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:215)
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:336)
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:381)
            at org.bukkit.craftbukkit.CraftServer.loadPlugin(CraftServer.java:250)
            at org.bukkit.craftbukkit.CraftServer.enablePlugins(CraftServer.java:232)
            at net.minecraft.server.MinecraftServer.t(MinecraftServer.java:371)
            at net.minecraft.server.MinecraftServer.a(MinecraftServer.java:358)
            at net.minecraft.server.MinecraftServer.init(MinecraftServer.java:187)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:422)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:492)
    Caused by: java.lang.ClassNotFoundException: MAPI.Databases.MySQL
            at java.net.URLClassLoader$1.run(Unknown Source)
            at java.net.URLClassLoader$1.run(Unknown Source)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(Unknown Source)
            at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:41)
            at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:29)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            ... 11 more

    Some lines of code like loading config are skipped and fine.
    Code:
       
     
    MySQL mysql;
        public void onEnable(){
            String host = getConfig().getString("server.host");
            String port = getConfig().getString("server.port");
            String user = getConfig().getString("server.username");
            String pass = getConfig().getString("server.password");
            String db = getConfig().getString("server.database");
     
            mysql = new MySQL(host, port, db, user, pass);  //<----- Error line
            mysql.open();
     
            if (mysql.getConnection() == null) {
                //It doesn't even get to that point
                Bukkit.getPluginManager().disablePlugin(this);
                return;
            }
        }

    I think it's looking for MAPI but it can't find it. Oh stupid me. Why must MySQL in Java be so hard for me ? :(
     
  14. Offline

    stelar7

    ah, I forgot that you need the plugin version xD
    put it in the plugins folder (LINK)
     

    Attached Files:

    lololmaker likes this.
  15. Offline

    lololmaker

    Life saver !!! :D

    You can't imagine my smile without those errors ! ;o
     
  16. Offline

    konesmeijer

    Can anybody please tell me how to install this I want this driver for this plugin http://dev.bukkit.org/server-mods/onlineusers/#comments to work on my server can anybody please tell my (easily) how to do this I have a remote Database and i'm willing to pay if you can help me!
     
  17. Offline

    stelar7

    JDBC driver is included in CraftBukkit
     
Thread Status:
Not open for further replies.

Share This Page