python,import cx_Oracle,,# 设置Oracle数据库连接参数,dsn = cx_Oracle.makedsn('host', port, service_name='service_name'),connection = cx_Oracle.connect(user='username', password='password', dsn=dsn),,# 创建游标对象,cursor = connection.cursor(),,# 执行SQL查询,cursor.execute("SELECT * FROM your_table"),,# 获取查询结果,for row in cursor:, print(row),,# 关闭游标和连接,cursor.close(),connection.close(),
``oci.h
,并链接对应的库文件。pyodbc
库。首先安装pyodbc
,然后使用以下代码:,``python,import pyodbc,conn = pyodbc.connect('DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=路径到你的数据库文件;'),cursor = conn.cursor(),
``Server.CreateObject
创建 ADO 对象,通过 Open
方法打开数据库连接。python,import pyodbc,,# 连接字符串,conn_str = (, r'DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};', r'DBQ=你的数据库文件路径;',),,# 创建连接,conn = pyodbc.connect(conn_str),cursor = conn.cursor(),,# 执行查询,cursor.execute("SELECT * FROM 你的表名"),,# 获取结果,rows = cursor.fetchall(),for row in rows:, print(row),,# 关闭连接,cursor.close(),conn.close(),
``Powered By Z-BlogPHP 1.7.3
Copyright Your WebSite.Some Rights Reserved.