Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem creating two connections #1

Closed
mattwg opened this issue Oct 26, 2014 · 4 comments
Closed

Problem creating two connections #1

mattwg opened this issue Oct 26, 2014 · 4 comments

Comments

@mattwg
Copy link

mattwg commented Oct 26, 2014

I am struggling to create two connections in a single python program. My use case is that I want to connect to a source database and a target database to move data around. My single program requires both connections to be live at the same time. I am trying to run this code in Python 2.7.5:

    import jaydebeapi as jdbc

    ct = jdbc.connect('com.teradata.jdbc.TeraDriver',
                     ['jdbc:teradata://vivaldi.vip.ebay.com', getpass.getuser(), p[0]],
                     ['/Library/Frameworks/R.framework/Versions/3.1/Resources/library/ebaytd/terajdbc4.jar',
                      '/Library/Frameworks/R.framework/Versions/3.1/Resources/library/ebaytd/tdgssconfig.jar'],)

    cm = jdbc.connect('com.mysql.jdbc.Driver',
                    ['jdbc:mysql://10.9.250.213:3306','root',p[0]],
                    ['/Users/magardner/Documents/Development/R/mysqljdbc/mysql-connector-java-5.1.33-bin.jar'],)

I get an error when the second call to jdbc.connect is made:

Traceback (most recent call last):
  File "/Users/magardner/PycharmProjects/ebayep-backend/process.py", line 82, in <module>
    main()
  File "/Users/magardner/PycharmProjects/ebayep-backend/process.py", line 61, in main
    ['/Users/magardner/Documents/Development/R/mysqljdbc/mysql-connector-java-5.1.33-bin.jar'],)
  File "/Users/magardner/untitled/lib/python2.7/site-packages/jaydebeapi/dbapi2.py", line 269, in connect
    jconn = _jdbc_connect(jclassname, jars, libs, *driver_args)
  File "/Users/magardner/untitled/lib/python2.7/site-packages/jaydebeapi/dbapi2.py", line 116, in _jdbc_connect_jpype
    jpype.JClass(jclassname)
  File "/Users/magardner/untitled/lib/python2.7/site-packages/jpype/_jclass.py", line 58, in JClass
    raise _RUNTIMEEXCEPTION.PYEXC("Class %s not found" % name)
jpype._jexception.RuntimeExceptionPyRaisable: java.lang.RuntimeException: Class com.mysql.jdbc.Driver not found

However if I comment out either of the jdbc.connect statements each runs successfully on it's own and allows me to connect to the relevant database. If I reverse the order of the jdbc.connect statements I still get the error on the second call.

I think this may have something to do with the way that JPype is being reused in the second call. Is this something I am doing wrong? Or is there a known issue here?

Thanks in advance for any suggestions,
Matt

@mattwg
Copy link
Author

mattwg commented Oct 26, 2014

Typical! I posted the question - had a swig of beer ;-) and realised what might be going on. I can only add the paths for finding the JDBC drivers once - so in effect I have to specify the path for all JDBC drivers my program requires in both calls to jdbc.connect(). So if I change the code to look like this it works a treat:

    import jaydebeapi as jdbc
    ct = jdbc.connect('com.teradata.jdbc.TeraDriver',
                     ['jdbc:teradata://vivaldi.vip.ebay.com', getpass.getuser(), p[0]],
                     ['/Library/Frameworks/R.framework/Versions/3.1/Resources/library/ebaytd/terajdbc4.jar',
                      '/Library/Frameworks/R.framework/Versions/3.1/Resources/library/ebaytd/tdgssconfig.jar',
                      '/Users/magardner/Documents/Development/R/mysqljdbc/mysql-connector-java-5.1.33-bin.jar'],)

    cm = jdbc.connect('com.mysql.jdbc.Driver',
                    ['jdbc:mysql://10.9.250.213:3306','root',p[0]],
                    ['/Library/Frameworks/R.framework/Versions/3.1/Resources/library/ebaytd/terajdbc4.jar',
                      '/Library/Frameworks/R.framework/Versions/3.1/Resources/library/ebaytd/tdgssconfig.jar',
                      '/Users/magardner/Documents/Development/R/mysqljdbc/mysql-connector-java-5.1.33-bin.jar'],)

FIxed! Not sure if this is technically a bug - but I am sure it will catch folks out.

Matt

@mattwg mattwg closed this as completed Oct 26, 2014
@baztian
Copy link
Owner

baztian commented Oct 26, 2014

Thank you Matt, I've opened #2 to find a solution to avoid such problems in the future.
BTW: Your second call to connect() can leave the jar parameter off. It won't get used with the current implementation.

@mattwg
Copy link
Author

mattwg commented Oct 26, 2014

Thanks. Yeah I figured the second call was redundant this morning!
On Oct 26, 2014 1:04 AM, "baztian" notifications@github.com wrote:

Thank you Matt, I've opened #2 to find a solution to avoid such problems
in the future.
BTW: Your second call to connect() can leave the jar parameter off. It
won't get used with the current implementation.


Reply to this email directly or view it on GitHub.

@pybokeh
Copy link

pybokeh commented Nov 25, 2020

This issue is a life saver! I was having the same issue and couldn't figure out why for the longest time. Now I know! I agree that a warning is needed for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants