我无法从我的Jython程序连接到数据库。纯Java程序可以连接,而我只能使用JDBC-ODBC桥从Jython连接到数据库:“sun.jdbc.odbc.JdbcOdbcDriver”。如果我使用本机JDBC驱动程序,我的程序将失败并出现“找不到驱动程序”异常。
代码:
import sys
from com.ziclix.python.sql import zxJDBC
connection1 = zxJDBC.connect( jdbc:odbc:test_odbc , postgres , postgres , sun.jdbc.odbc.JdbcOdbcDriver )
print "JDBC:ODBC connection set"
connection2 = zxJDBC.connect( jdbc:postgresql://127.0.0.1/test?stringtype=unspecified , postgres , postgres , org.postgresql.Driver )
print "JDBC native connection set"
输出
C: oolspyscriptsscriptsdb_examples>jython --version
Jython 2.5b1 (trunk:5903:5905, Jan 9 2009, 16:01:29)
[Java HotSpot(TM) Client VM (Sun Microsystems Inc.)] on java1.6.0_11
C: oolspyscriptsscriptsdb_examples>jython pg_test.py
JDBC:ODBC connection set
Traceback (most recent call last):
File "pg_test.py", line 6, in <module>
connection2 = zxJDBC.connect( jdbc:postgresql://127.0.0.1/test?stringtype=un
specified , postgres , postgres , org.postgresql.Driver )
zxJDBC.DatabaseError: driver [org.postgresql.Driver] not found
I think that my CLASSPATH is set properly while native Java programs can connect to this database using native driver. I have found that all JDBC drivers have .pkc files in cachedirpackages.
我应该设置什么来获取数据库连接?