473,549 Members | 2,584 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Jython: cannot import Java packages

4 New Member
Hello,
I developed some useful Jython script in Eclipse, using ojdbc6.jar as driver library (attached to the project as "external library"). When debugging in Eclipse, everything goes fine. Also standalone run on the development PC runs OK.

Then I copied the complete Jython 2.5.2 installation to another machine (with Java JRE 1.6.30), copied my script and the ojdbc6.jar library in the same directory as the script.

I call it with

<pathtojava>\ja va.exe -cp ojdbc6.jar -jar ..\jython2.5.2\ jython.jar myscript.py (which works on the original PC)

Now, it throws exception in this code:

from oracle.jdbc import OracleDriver
...
class SqlTester:
...
def connect( self ):
self.driver = OracleDriver()
self.connection = DriverManager.g etConnection( "jdbc:oracle:th in:@%s:%s:%s" % ( self.host, self.port, self.sid ), self.user, self.psw )
...

The exception is:

Traceback (most recent call last):
File "myscript.p y", line 119, in <module>
tester.run_all_ tests()
File "myscript.p y", line 79, in run_all_tests
self.connect()
File "myscript.p y", line 60, in connect
self.connection = DriverManager.g etConnection( "jdbc:oracle:th in:@%s:%s:%s" % ( self.host, self.port, self.sid )
at java.sql.Driver Manager.getConn ection(Unknown Source)
at java.sql.Driver Manager.getConn ection(Unknown Source)
at sun.reflect.Nat iveMethodAccess orImpl.invoke0( Native Method)
at sun.reflect.Nat iveMethodAccess orImpl.invoke(U nknown Source)
at sun.reflect.Del egatingMethodAc cessorImpl.invo ke(Unknown Source)
at java.lang.refle ct.Method.invok e(Unknown Source)
java.sql.SQLExc eption: java.sql.SQLExc eption: No suitable driver found for jdbc:oracle:thi n:@xxxxxx:1521: DWH

What am I doing wrong?
Apr 2 '12 #1
3 4900
sourabh mittal
7 New Member
Hi! well i'm going to start using jython which i planned already as addicted to easiness of python and performance of java! I don't know but i'm 100% sure this may help you! download this pdf book "The definite guide to Jython and read the importing java packages part. This book also provides precautions while importing java packages! and please also reply my post about java multiplatform deployment! please reply! It's a direct link! you can also resume it using Internet download manager!

Link : http://serek.eurotrip.pl/Android_boo...20(Apress).pdf
Apr 2 '12 #2
Jindra
4 New Member
Hello,
finally resolved. It is not an import problem (driver imports OK, when instantiated, call to main() prints driver info).

The real problem is non-functional java.sql.Driver Manager in Jython

java.sql.Driver Manager.getConn ection() will always report "no suitable driver found" or similar, depending if it is Java 5 or Java 6.

The solution is very simple: since I have the OracleDriver class already imported, I just use it:

drv = OracleDriver()
connection = drv.connect( myJdbcUrl, java.util.Prope rties() )

In Python you can easily select and instantiate your java.sql.Driver for any database connection dynamically. So you don't need java.sql.Driver Manager, which was actually invented in Java to allow for dynamic driver selection...

I am only puzzled by one thing. This DriverManager problem seems to be the most frequent problem in Jython when using JDBC. Yet, I have not seen a single answer (on Google) to describe the correct way how to use JDBC; on the contrary, jython tutorials I saw all copy the Java stuff using DriverManager. Have nobody ever made any test to see whether what they teach is true?
Apr 3 '12 #3
satishmoningi
1 New Member
Hi Jindra,
I am also facing same issue with following jython script. Could you please verify where I went wrong.
Expand|Select|Wrap|Line Numbers
  1. from java.lang import Class
  2. import sys
  3. from java.util import Properties
  4. sys.path.append('/opt/IBM/WASLogs/shared-libs/ojdbc6.jar')
  5. from oracle.jdbc import OracleDriver
  6.  
  7.  
  8. driver = OracleDriver()
  9. myJdbcUrl = "jdbc:oracle:thin:@localhost:2347:PRBPMDB1"
  10. info = Properties()
  11. info.put ("user", "user");
  12. info.put ("password","user1");
  13. conn = driver.connect(myJdbcUrl,info)
  14. stmt = conn.createStatement()
  15. rs = stmt.executeQuery("select * from wom_message_status where id=1067")
  16.  
  17. while rs.next():
  18.         print "%s" % rs.getString(3)
  19.  
  20. rs.close()
  21. stmt.close()
  22. conn.close()
  23.  
  24.  
Thanks,
Satish Moningi
+91 7893742724
Apr 25 '17 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2294
by: Mako Klaic | last post by:
what is java package? (for exaple javax.servlet) where are located package files? what file type is a package? im trying to include a package javax.servlet.http i have intalled both J2SE and J2EE, bunt i can't compile a source with this line of code: import javax.servlet.http or other.....
1
14595
by: ProgDario | last post by:
Hello, in the site I found a lot of complicated examples, but I can't find the simple one I'm looking for. The problem is: I have 1 jython file (script1.py) with a function named 'calculate', and a java file (run.java).
0
6898
by: Stian Søiland | last post by:
all examples performed with: Python 2.3+ (#2, Aug 10 2003, 11:09:33) on linux2 (2, 3, 0, 'final', 1) This is a recursive import:
2
3531
by: Marc Ederis | last post by:
Hello, I'm trying to create an executable with py2exe, and it uses the odbc module. The script runs fine until I use py2exe on it and run the ..exe. Then I get: -- Traceback (most recent call last): File "dbmod.py", line 2, in ? File "odbc.pyo", line 9, in ?
1
2213
by: Raja | last post by:
I have a java class thats trying to call something in python. This works fine when i do a jythonc on the python script. When i call another python script from the __init__ of my called python script, things go bad.i get this message AttributeError: class 'configuration' has no attribute 'configuration' when calling the constructor. This is...
4
3413
by: angel | last post by:
A java runtime environment includes jvm and java class (for example classes.zip in sun jre). Of course jython need jvm,but does it need java class. Thanx
2
9206
by: Kent Lewandowski | last post by:
hi all, Recently I wrote some stored procedures using java jdbc code (admittedly my first stab) and then tried to implement the same within java packages (for code reuse). I encountered problems doing this. I wanted to implemented a generic "Helper" class like this: /** * Helper
3
2296
by: geir.smestad | last post by:
Using Ubuntu Breezy Badger 5.10. I get the following traceback: ----- Traceback (most recent call last): File "/home/geir/programmering/htmlparse/formatter.py", line 1, in -toplevel- import formatter File "/home/geir/programmering/htmlparse/formatter.py", line 2, in -toplevel- import htmllib
2
12408
by: HMS Surprise | last post by:
Greetings. What is the implication of the error message 'cannot import name .....'? It occurs when executing the line: from nBaseTest import nBaseTest The file exists and the class within it exists. Changing it to from nBaseTest import x
7
12326
jhardman
by: jhardman | last post by:
So I'm trying to use regular expressions, but my compiler keeps failing at import java.util.regex.*; I know that the regex package is supposed to be there, every reference I have found put it right there. Intellisense recognizes java.util and suggests several classes within it (timer, random, etc), but nothing after that. The truth is, I have...
0
7457
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7723
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7965
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7817
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5375
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5092
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3504
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3487
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1949
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.