GitHub:https://github.com/baztian/jaydebeapi
1.安装:pip install JayDeBeApi
2.下载JDBC的jar包,事实上如果是用的DataGroup,可以直接拷出来使用
3.使用 jaydebeapi.connect 连接数据库
参数:
连接mysql
import jaydebeapi
driver = ‘com.mysql.jdbc.Driver‘
url = ‘jdbc:mysql://*.*.*.*:3306/api_test_v3?characterEncoding=UTF8&serverTimezone=Asia/Shanghai‘
user = ‘root‘
password = ‘Admin123@qwe‘
jarFile = r‘mysql-connector-java-5.1.47.jar‘
conn = jaydebeapi.connect(jclassname=driver, url=url, driver_args=[user, password], jars=jarFile)
curs = conn.cursor()
curs.execute(‘select * from users‘)
result = curs.fetchall()
print(result)
curs.close()
连接oracle
import jaydebeapi
url = ‘jdbc:oracle:thin:@//*.*.*.*:1521/db1‘
driver = ‘oracle.jdbc.driver.OracleDriver‘
user = ‘****‘
password = ‘****‘
jarFile = r‘ojdbc8.jar‘
conn = jaydebeapi.connect(jclassname=driver, url=url, driver_args=[user, password], jars=jarFile)
curs = conn.cursor()
curs.execute(‘select * from *** where ID = -1‘)
result = curs.fetchall()
print(result)
curs.close()