finding a java class using Jython

2009-08-21
2013-03-15
  • Roy Bleasdale

    Roy Bleasdale - 2009-08-21

    I am a beginner and have had some success with Python and pydev and wanted to use Jython and DB2 JDBC in pydev.

    I found some sample code which works fine at the command prompt but not within pydev

    Class.forName("COM.ibm.db2.jdbc.app.DB2Driver").newInstance()
    con = DriverManager.getConnection( 'jdbc:db2:sample','db2admin','password')

    When I run it claims it cannot find the class

    java.lang.ClassNotFoundException: java.lang.ClassNotFoundException: COM.ibm.db2.jdbc.app.DB2Driver

    I have added the DB2 jar files and folder  to PYTHONPATH libraries and added them to the module folder. All to no avail.

    Can anybody tell me how I can persuade pydev to find the jars

    Thanks

     
    • Fabio Zadrozny

      Fabio Zadrozny - 2009-08-21

      I checked the Class.forName and it works for me when adding a jar to the pythonpath... are you sure the path is correct?

      Another thing, I find it really strange that  the 'COM' is added there in uppercase and not in lowercase (are you sure that's correct?)

      Also, you don't need the newinstance() there (just doing the forName should be enough).

      Cheers,

      Fabio

       
    • Roy Bleasdale

      Roy Bleasdale - 2009-08-24

      Despite its unusual look COM is correct.

      If I run
          jython example.py
      at the command prompt then the class is found.

      I have re-added the db2 jars to pythonpath library and when I run
      *sys-package-mgr*: processing new jar shows in the console

      I wondered if there is a Java path I need to add the jars to?

      Cheers,

      Roy

       
      • Fabio Zadrozny

        Fabio Zadrozny - 2009-08-24

        Can you add:

        import sys
        for p in sys.path: print p

        From both the command prompt and from eclipse and paste the results for each one?

        Cheers,

        Fabio

         
    • Roy Bleasdale

      Roy Bleasdale - 2009-08-25

      At the Command Prompt:

      C:\eclipseWorkspacesPy\TADzJy\src\tools>jython exam2.py
      C:\eclipseWorkspacesPy\TADzJy\src\tools
      C:\jython2.5.0\Lib
      __classpath__
      __pyclasspath__/
      C:\jython2.5.0\Lib\site-packages
      my program
      passed connection

      From Eclipse:

      C:\eclipseWorkspacesPy\TADzJy\src\tools
      C:\eclipseWorkspacesPy\TADzJy\src
      C:\jython2.5.0\Lib
      C:\jython2.5.0\Lib\site-packages
      C:\Program Files\IBM\Java50\jre\lib\vm.jar
      C:\Program Files\IBM\Java50\jre\lib\core.jar
      C:\Program Files\IBM\Java50\jre\lib\charsets.jar
      C:\Program Files\IBM\Java50\jre\lib\graphics.jar
      C:\Program Files\IBM\Java50\jre\lib\security.jar
      C:\Program Files\IBM\Java50\jre\lib\ibmpkcs.jar
      C:\Program Files\IBM\Java50\jre\lib\ibmorb.jar
      C:\Program Files\IBM\Java50\jre\lib\ibmcfw.jar
      C:\Program Files\IBM\Java50\jre\lib\ibmorbapi.jar
      C:\Program Files\IBM\Java50\jre\lib\ibmjcefw.jar
      C:\Program Files\IBM\Java50\jre\lib\ibmjgssprovider.jar
      C:\Program Files\IBM\Java50\jre\lib\ibmjsseprovider2.jar
      C:\Program Files\IBM\Java50\jre\lib\ibmjaaslm.jar
      C:\Program Files\IBM\Java50\jre\lib\ibmjaasactivelm.jar
      C:\Program Files\IBM\Java50\jre\lib\ibmcertpathprovider.jar
      C:\Program Files\IBM\Java50\jre\lib\server.jar
      C:\Program Files\IBM\Java50\jre\lib\xml.jar
      C:\Program Files\IBM\Java50\jre\lib\ext\CmpCrmf.jar
      C:\Program Files\IBM\Java50\jre\lib\ext\dtfj-interface.jar
      C:\Program Files\IBM\Java50\jre\lib\ext\dtfj.jar
      C:\Program Files\IBM\Java50\jre\lib\ext\gskikm.jar
      C:\Program Files\IBM\Java50\jre\lib\ext\ibmcmsprovider.jar
      C:\Program Files\IBM\Java50\jre\lib\ext\ibmjcefips.jar
      C:\Program Files\IBM\Java50\jre\lib\ext\ibmjceprovider.jar
      C:\Program Files\IBM\Java50\jre\lib\ext\ibmkeycert.jar
      C:\Program Files\IBM\Java50\jre\lib\ext\IBMKeyManagementServer.jar
      C:\Program Files\IBM\Java50\jre\lib\ext\ibmpkcs11.jar
      C:\Program Files\IBM\Java50\jre\lib\ext\ibmpkcs11impl.jar
      C:\Program Files\IBM\Java50\jre\lib\ext\ibmsaslprovider.jar
      C:\Program Files\IBM\Java50\jre\lib\ext\indicim.jar
      C:\Program Files\IBM\Java50\jre\lib\ext\jaccess.jar
      C:\Program Files\IBM\Java50\jre\lib\ext\JawBridge.jar
      C:\Program Files\IBM\Java50\jre\lib\ext\jdmpview.jar
      C:\jython2.5.0\db2jcc.jar
      my program
      Traceback (most recent call last):
        File "C:\eclipseWorkspacesPy\TADzJy\src\tools\exam2.py", line 24, in <module>
          Start()
        File "C:\eclipseWorkspacesPy\TADzJy\src\tools\exam2.py", line 15, in Start
          Class.forName("COM.ibm.db2.jdbc.app.DB2Driver")
          at java.lang.Class.forName(Class.java:130)

          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)

          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

          at java.lang.reflect.Method.invoke(Method.java:615)

      java.lang.ClassNotFoundException: java.lang.ClassNotFoundException: COM.ibm.db2.jdbc.app.DB2Driver

      Hope this helps.

      Cheers,

      Roy

       

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks