python 连接hana数据库
时间: 2023-10-13 18:14:59 浏览: 45
可以使用pyhdb模块来连接hana数据库,示例代码如下:
```
import pyhdb
conn = pyhdb.connect(
host="hostname",
port=port_number,
user="username",
password="password"
)
cursor = conn.cursor()
cursor.execute("SELECT * FROM table_name")
result = cursor.fetchall()
print(result)
conn.close()
```
其中,`hostname`为hana数据库的主机名,`port_number`为hana数据库的端口号,`username`和`password`为hana数据库的凭据。在连接成功之后,可以使用`cursor`对象来执行SQL查询,并通过`fetchall`方法获取查询结果。最后,记得关闭数据库连接。