IT运维笔记


python 连接数据库之jaydebeapi

让python通过jdbc连接数据库 1、安装visualcppbuildtools_full.exe 链接:https://pan.baidu.com/s/1MLxNJfWNGuKIxgNYkJgUnw 密码:3etc 2、pip install JayDeBeApi https://pypi.org/project/JayDeBeApi/ 3、测试代码
import jaydebeapi

url = 'jdbc:oracle:thin:@127.0.0.1:1521/orcl'
user = 'hwf_model'
password = 'hwf_model'
dirver = 'oracle.jdbc.driver.OracleDriver'
jarFile = 'E:\\pycharm\\lib\\ojdbc14.jar'
sqlStr = 'select * from dual'
#conn=jaydebeapi.connect('oracle.jdbc.driver.OracleDriver','jdbc:oracle:thin:@127.0.0.1:1521/orcl',['hwf_model','hwf_model'],'E:/pycharm/lib/ojdbc14.jar')
conn = jaydebeapi.connect(dirver, url, [user, password], jarFile)
curs = conn.cursor()
curs.execute(sqlStr)
result = curs.fetchall()
print(result)
curs.close()
conn.close()