python 操作达 梦数据库
python 达梦数据库操作流程
- 连接数据库 dm.connect( ... )
- 获取游标 dm_conn.cursor()
- 编写SQL语句 sql_str
- 执行SQL语句 dm_cursor.execute()
- 获取结果列表 dt_breakpoint = dm_cursor.fetchall()
- 关闭游标 dm_cursor.close()
- 关闭数据库连接 dm_conn.close()
代码示例
import pandas as pd import numpy as np import datetime import dmPython as dm user_name = "dameng" passwd = "admin" server_name = "LOCALHOST" server_port = 5236 def query_ustpf_time_breakpoint( wf_no ): dm_conn = dm.connect( user=user_name, password=passwd, server=server_name, port=server_port ) dm_cursor = dm_conn.cursor() sql_str = "select MAIN_LF_4H_PROC_TIME from WF_ST_PF_PARA where WINDPLANT_NO=%d;" % ( wf_no ) print( "func(query_ustpf_time_breakpoint):", sql_str ) try: dm_cursor.execute( sql_str ) except Exception as e: print( ‘func(query_ustpf_time_breakpoint) -- dm_cursor.execute(...) Error: ‘, e ) dt_breakpoint = dm_cursor.fetchall() dm_cursor.close() dm_conn.close() if len( dt_breakpoint ) > 0: return dt_breakpoint[0][0] else: return None
备注
预先安装达梦数据库python语言支持包dmPython。
相关推荐
YENCSDN 2020-11-17
lsjweiyi 2020-11-17
houmenghu 2020-11-17
Erick 2020-11-17
HeyShHeyou 2020-11-17
以梦为马不负韶华 2020-10-20
lhtzbj 2020-11-17
夜斗不是神 2020-11-17
pythonjw 2020-11-17
dingwun 2020-11-16
lhxxhl 2020-11-16
坚持是一种品质 2020-11-16
染血白衣 2020-11-16
huavhuahua 2020-11-20
meylovezn 2020-11-20
逍遥友 2020-11-20
weiiron 2020-11-16