首页 > 数据库技术 > 详细

python 连接HANA库,写入城乡划分代码(省市县镇乡村5级)到数据库

时间:2019-01-14 13:49:59      阅读:313      评论:0      收藏:0      [点我收藏+]
 1 import pyhdb,re
 2 def get_connection():
 3     conn_obj = pyhdb.connect(
 4         host = "xxx.172.1.xxx", #HANA地址
 5         port = 30015, #HANA端口号
 6         user = "xxxxx", #用户号
 7         password = "xxxxx" #密码
 8     )
 9     return conn_obj
10 def get_mat(conn,exec_str):
11     cursor = conn.cursor()
12     cursor.execute(exec_str) #连接表和视图都可以
13     return cursor
14 conn = get_connection()
15 file_str = D:\city_2017.txt
16 with open(file_str, r, encoding=gb18030) as f:
17     lines = f.readlines()
18     for i in lines:
19         try:
20             upsert_str = UPSERT HC_BI_DW.BI_DIM_BASE_PROVINCIAL_CITY VALUES (+str(re.split("\[|]",i)[1])+) WITH PRIMARY KEY;
21             print(upsert_str)
22             mats = get_mat(conn,upsert_str)
23             conn.commit()
24         except BaseException as e:
25             print(错误:, e)

 

python 连接HANA库,写入城乡划分代码(省市县镇乡村5级)到数据库

原文:https://www.cnblogs.com/Magicn/p/10265928.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!