Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • Connecting to MySQL Database


    Banker

    Recommended Posts

    Hey, so im working on a script for myself and a friend which i am needing to have connect to a database (MySQL). When i try using the driver "com.mysql.jdbc.Driver" once i catch the error and log it, the output is just "com.mysql.jdbc.Driver" when i add the connector .jar to my buildpath nothing changes.

     

    I have also tried a method which requires the same .jar file and just gets stuck on the

    MysqlDataSource dataSource = new MysqlDataSource();
    

    When i can connect to the database itself i have querys and everything prepared, its just the actual connecting to the database that is my issue.

     

    Any help is appreciated, i can provide more code and errors as needed.

     

    Thanks,

     ~ Banker

    Link to comment
    Share on other sites

    Do you have a stack trace?

     

    Also, if this is for a public script I would stay far away from directly access a database from the script.

     

    • [iNFO]22:41:55: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:264) at com.banker.main.Main.onStart(Main.java:27) at org.dreambot.api.script.AbstractScript.run(AbstractScript.java:183) at java.lang.Thread.run(Thread.java:745)   

     

    And its a private script so im not too concerned about directly accessing the database

    Link to comment
    Share on other sites

     

    • [iNFO]22:41:55: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:264) at com.banker.main.Main.onStart(Main.java:27) at org.dreambot.api.script.AbstractScript.run(AbstractScript.java:183) at java.lang.Thread.run(Thread.java:745)   

     

    And its a private script so im not too concerned about directly accessing the database

     

     

     

    You need to include the source in your script, instead of link to the JAR.

    Link to comment
    Share on other sites

    You need to include the source in your script, instead of link to the JAR.

     

    where would i find the source, when i expand the jar contents and find the Driver.class there is no code inside and im prompted to "Attach source..."

     

    Also where would i have the source, in the main class or create another Driver class etc?

     

     

    EDIT: I have the source for Driver.class, where would i have this source? (In a class in my main package, in the main class?)

    Link to comment
    Share on other sites

    Build path

     

    How,  cant just link to the class itself as it requires a few other things referenced in other classes of the .jar

    Link to comment
    Share on other sites

    ... add the .jar to your Build path

     

    Having the jar in the build path doesn't help in getting the driver. I still get the same errors in running with and without the jar in the build path.

     

    With another method i tried using the same jar file, once it hit the block of code it just stopped and refused to go further. (As stated in the initial post)

    Link to comment
    Share on other sites

    • 1 year later...

    is this issue has solved ?

    i've tried and followed some tutorial how to connect to mysql using jdbc driver, it did connect to the database and retrieve some data.. but unfortunately it works for like once or several times when i ran the script then it got stuck (do nothing at the debug console). i have to re-run mysql server and re-launch the client. for the fresh run it works and then stuck again.. and again..  i appreciate for any suggestion..

    Link to comment
    Share on other sites

    • 2 weeks later...
    On 9/13/2018 at 1:33 AM, fort35 said:

    is this issue has solved ?

    i've tried and followed some tutorial how to connect to mysql using jdbc driver, it did connect to the database and retrieve some data.. but unfortunately it works for like once or several times when i ran the script then it got stuck (do nothing at the debug console). i have to re-run mysql server and re-launch the client. for the fresh run it works and then stuck again.. and again..  i appreciate for any suggestion..

     

    I've not managed to solve this - however I will be looking into it in the near future and post a solution :)

    Link to comment
    Share on other sites

    Archived

    This topic is now archived and is closed to further replies.

    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.