Using MySQL

Discussion in 'Plugin Development' started by Mariusz, Feb 6, 2011.

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



    I'm developing a plugin that uses MySQL but unfortunately I'm unable to use MySQL -.-

    I've done everything as in this movie:

    The problem is function:
    Returns an error:
    java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
    Any suggestions?
  2. Offline


    thats my:

    import java.sql.*;
    public class GmodDataBase
        protected Connection connection;
        public String url = "jdbc:mysql://localhost:3306/";
        public String dba = "********";
        public String driver = "com.mysql.jdbc.Driver";
            public GmodDataBase()
                   connection = DriverManager.getConnection(url+dba,"username","password");
                catch(Exception e)
            public Connection getConnection()
              return connection;
    --- merged: Feb 6, 2011 9:09 PM ---
    ohh and u need to place the connector library to the plugin!
  3. Offline


    It just keep saying the same. I'm putting connector in there as "add External JAR's". I'm using Eclipse...
  4. Offline


    Edit your Manifest
    Manifest-Version: 1.0
    Class-Path: ../mysql-connector-java-bin.jar
    Also ensure you have the connector in root. :)
  5. Offline


    Nothing... funny thing is it's working when I'm creating java application but not with plugin -.-

    Ehm... Actually i made it work by putting conector into plugins folder. It's not what i want to do because my server tried to run it as a plugin. Any suggestions? >.<
    --- merged: Feb 7, 2011 9:45 PM ---
    I fixed it by editing manifest file:

    Manifest-Version: 1.0
    Class-Path: mysql-connector-java-bin.jar
    Not as Samkio said
    Manifest-Version: 1.0
    Class-Path: ../mysql-connector-java-bin.jar
    Now it actually looks for connector in serwer path.
  6. Offline


    May I ask what Manifest file I should edit? I keep getting the same error. (java.lang.ClassNotFoundException: com.mysql.jdbc.Driver)

    Nevermind, got it working.
    If anyone new like me gets in this topic and also can't get it to work or knows what manifest file they talk about.. It's the in your META-INF folder in your plugin.jar.
  7. Offline

    Joshua Burt

    This was a great tip, thank you!
  8. Offline


    I couldn't get the META-INF manifest file to change/update no matter what I did however dropping the mysql jar file into the ext directory for java worked.
  9. Offline


    I have now tried to get MySQL to work for more than 20 hours, but I still can't get it to work.
    Is there a good tutorial to setup MySQL on a plugin?

    I have tried the following
    • Connect to the jar file trough the above example with Class-Path in the Manifest file
    • External find the file and load the file using ClassLoader
    And a lot of other ideas and examples I have found on the internet but without luck.
    With the ClassLoader I found the file, but Class.forName still returns an error about the Class not found and the connecting returns "No suitable driver found for..."
  10. Offline


    I recommend you to follow the video in OP exactly to every point. That's how I got it to work. And oh, edit the .mf file and drag it in your .jar.
  11. Offline


    Still no luck.
    I followed the youtube video and edited the Manifest file but I still get the ClassNotFound error in console.
  12. Offline


    What I did, was make a subfolder for my plugin in the plugin folder. My plugin is called wabxp.
    So in the manifest, I put:
    Class-Path: wabxp/mysql-connector-java-bin.jar
  13. Offline


    Sry the late response, it still don't work for me.
  14. Offline


    Hey there. im actually developing a sql based plugin as well called theBasics. As i think others have said before, the classpath isn't set correctly. To make things easier, simply put the mysql_connector_bin jar into this folder
    (if in windows)
    C:\Program Files\Java\jre6\lib\ext

    This will work without having to set the class path. If you have installed multiple versions of java on your system, be sure to put it in the folder your bukkit server actually uses. Also, remember that whoever wishes to use the mod will have to do the same thing.

    One other thing... if using linux it will be in a different folder of course, but the final part should always be
  15. Offline


    That's working, thanks! :)
    NOTE: When using Windows 64-bit, check if Java is installed for 32 or 64-bit. If 32-bit, it's in C:\Program Files (x86)\Java\jre6\lib\ext
Thread Status:
Not open for further replies.

Share This Page