Using zxJDBC with jython not working
Question: since I wanted to transform data storage for my recent Minecraft Python/Jython
Bukkit plugins from flat file to MySQL database I started googling. Tried
sqlite3 and MySQLd for Python but without success, so after few hours of
searching StackOverflow I came up to this question and answer, which SHOULD
solve my problem, since it's same thing. I tried to follow steps given in
[this answer](http://stackoverflow.com/a/10340498/2874447) , but without any
success due to this error:

    
    
    [15:31:45 WARN]: org.bukkit.plugin.InvalidPluginException: Traceback (most recen
    t call last):
    File "<iostream>", line 10, in <module>
    zxJDBC.DatabaseError: unable to instantiate datasource
    
    [15:31:45 WARN]:        at net.lahwran.bukkit.jython.PythonPluginLoader.loadPlug
    in(PythonPluginLoader.java:296)
    [15:31:45 WARN]:        at net.lahwran.bukkit.jython.PythonPluginLoader.loadPlug
    in(PythonPluginLoader.java:113)
    [15:31:45 WARN]:        at net.lahwran.bukkit.jython.PythonPluginLoader.loadPlug
    in(PythonPluginLoader.java:83)
    [15:31:45 WARN]:        at org.bukkit.plugin.SimplePluginManager.loadPlugin(Simp
    lePluginManager.java:305)
    [15:31:45 WARN]:        at com.master.bukkit.python.PythonLoader.onLoad(PythonLo
    ader.java:113)
    [15:31:45 WARN]:        at org.bukkit.craftbukkit.v1_7_R1.CraftServer.loadPlugin
    s(CraftServer.java:260)
    [15:31:45 WARN]:        at org.bukkit.craftbukkit.v1_7_R1.CraftServer.reload(Cra
    ftServer.java:628)
    [15:31:45 WARN]:        at org.bukkit.Bukkit.reload(Bukkit.java:279)
    [15:31:45 WARN]:        at org.bukkit.command.defaults.ReloadCommand.execute(Rel
    oadCommand.java:23)
    [15:31:45 WARN]:        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCo
    mmandMap.java:192)
    [15:31:45 WARN]:        at org.bukkit.craftbukkit.v1_7_R1.CraftServer.dispatchCo
    mmand(CraftServer.java:542)
    [15:31:45 WARN]:        at org.bukkit.craftbukkit.v1_7_R1.CraftServer.dispatchSe 
    rverCommand(CraftServer.java:529)
    [15:31:45 WARN]:        at net.minecraft.server.v1_7_R1.DedicatedServer.aw(Dedic
    atedServer.java:286)
    [15:31:45 WARN]:        at net.minecraft.server.v1_7_R1.DedicatedServer.u(Dedica
    tedServer.java:251)
    [15:31:45 WARN]:        at net.minecraft.server.v1_7_R1.MinecraftServer.t(Minecr
    aftServer.java:541)
    [15:31:45 WARN]:        at net.minecraft.server.v1_7_R1.MinecraftServer.run(Mine
    craftServer.java:453)
    [15:31:45 WARN]:        at net.minecraft.server.v1_7_R1.ThreadServerApplication.
    run(SourceFile:617)
    

Code I used that caused error above:

    
    
    from com.ziclix.python.sql import zxJDBC
    
    params = {}
    params['serverName'] = 'host'
    params['databaseName'] = 'dbname'
    params['user'] = "username"
    params['password'] = "pw"
    params['port'] = 3306
    db = apply(zxJDBC.connectx, ("org.gjt.mm.mysql.MysqlDataSource",), params)
    

Also, I tried this code:

    
    
    from com.ziclix.python.sql import zxJDBC
    
    d, u, p, v = "jdbc:mysql://host", "root", "pw", "org.gjt.mm.mysql.Driver"
    db = zxJDBC.connect(d, u, p, v)
    

but it caused this error:

    
    
    [15:37:20 WARN]: Caused by: Traceback (most recent call last):
    File "<iostream>", line 13, in <module>
    zxJDBC.DatabaseError: driver [org.gjt.mm.mysql.Driver] not found
    
    [15:37:20 WARN]:        at org.python.core.PyException.doRaise(PyException.java:
    200)
    [15:37:20 WARN]:        at org.python.core.Py.makeException(Py.java:1239)
    [15:37:20 WARN]:        at org.python.core.Py.makeException(Py.java:1243)
    [15:37:20 WARN]:        at com.ziclix.python.sql.zxJDBC.makeException(zxJDBC.jav
    a:328)
    [15:37:20 WARN]:        at com.ziclix.python.sql.connect.Connect.__call__(Connec
    t.java:78)
    [15:37:20 WARN]:        at org.python.core.PyObject.__call__(PyObject.java:441)
    [15:37:20 WARN]:        at org.python.core.PyObject.__call__(PyObject.java:447)
    [15:37:20 WARN]:        at org.python.pycode._pyx5.f$0(<iostream>:15)
    [15:37:20 WARN]:        at org.python.pycode._pyx5.call_function(<iostream>)
    [15:37:20 WARN]:        at org.python.core.PyTableCode.call(PyTableCode.java:165
    )
    [15:37:20 WARN]:        at org.python.core.PyCode.call(PyCode.java:18)
    [15:37:20 WARN]:        at org.python.core.Py.runCode(Py.java:1275)
    [15:37:20 WARN]:        at org.python.util.PythonInterpreter.execfile(PythonInte
    rpreter.java:235)
    [15:37:20 WARN]:        at org.python.util.PythonInterpreter.execfile(PythonInte
    rpreter.java:230)
    [15:37:20 WARN]:        at net.lahwran.bukkit.jython.PythonPluginLoader.loadPlug
    in(PythonPluginLoader.java:244)
    [15:37:20 WARN]:        ... 16 more
    

**What I acutally did (step-by-step)?**

I downloaded zipped mysql connector/J from [this
link](http://dev.mysql.com/downloads/connector/j/3.1.html) (as given in answer
from already linked S.O. question), unzipped it, copied "mysql-connector-
java-3.1.14-bin.jar" from it, pasted it to this path
"C:\Users\my_name\Documents\1.7.2twistedjobs\plugins\MySQL_jython". After, I
opened Control Panel, clicked System, went to Advanced system settings,
clicked Environment variables button, added new named CLASSPATH (since there
was no variable by that name), and set this path as value
"C:\Users\my_name\Documents\1.7.2twistedjobs\plugins\MySQL_jython\mysql-
connector-java-3.1.14-bin.jar", clicked OK.

NOTE: There was no import errors because of zxJDBC, which is strange, since it
obviously successfully imported it, but couldn't find drivers...

Thanks in advance!


Answer: Your second snippet of code should work. It works on my machine. What you
appear to have is a CLASSPATH issue. You might try putting your MySQL driver
jar file in the extensions directory, which on Windows you would find here:

    
    
    %SystemRoot%\Sun\Java\lib\ext 
    

The driver would then be available to all of your Java applications (if that's
what you want). Details are in Oracle's documentation:

<http://docs.oracle.com/javase/tutorial/ext/basics/install.html>

I want to make a couple of other points. First, even though the driver will
work with the name you gave it, you may eventually want to change it from
`org.gjt.mm.mysql.Driver` to `com.mysql.jdbc.Driver`, which is the modern,
renamed version. (If you're interested as to why, the details are here:
<http://stackoverflow.com/a/5808184/155167>.)

Your first snippet of code will not work, as there is no `MysqlDataSource`
class in the `org.gjt.mm.mysql` package. That class you reference is actually
here: `com.mysql.jdbc.jdbc2.optional.MysqlDataSource`, but I don't know if
_that_ snippet will work.

Like I said, put the MySQL driver jar in your CLASSPATH correctly, and it
should work. The Oracle documentation on CLASSPATH setup is here:

<http://docs.oracle.com/javase/tutorial/essential/environment/paths.html>
<http://docs.oracle.com/javase/8/docs/technotes/tools/windows/classpath.html>

Good luck!

