Python連接達夢數(shù)據庫的實現(xiàn)示例
python如果想連接達夢數(shù)據庫,必須要安裝dmPython。
簡介:dmPython 是 DM 提供的依據 Python DB API version 2.0 中 API 使用規(guī)定而開發(fā)的數(shù)據庫訪問接口。dmPython 實現(xiàn)這些 API,使 Python 應用程序能夠對 DM 數(shù)據庫進行訪問。
dmPython 通過調用 DM DPI 接口完成 python 模塊擴展。在其使用過程中,除 Python 標準庫以外,還需要 DPI 的運行環(huán)境。
第一步:使用源碼包方式安裝
進入達夢數(shù)據庫安裝目錄下的 dmPython 目錄,執(zhí)行命令 python setup.py install
注意:前提需要你有C++環(huán)境,Visual Studio。
出現(xiàn)上面這些信息代表安裝成功。
第二步:配置dpi環(huán)境變量
第三步:3.8及以上版本需操作
第四步:復制操作
將達夢數(shù)據庫安裝目錄中的drivers/dpi下的所有文件復制到D:\python\python3.9\Lib\site-packages\dmPython-2.4.5-py3.9-win-amd64.egg下。
第五步:編寫python查詢達夢數(shù)據庫代碼進行測試
# coding:utf-8 import dmPython try: # 創(chuàng)建達夢數(shù)據庫連接 conn = dmPython.connect(user='TEST', password='abc123456', server='localhost', port=5236) # 創(chuàng)建數(shù)據庫操作對象 cursor = conn.cursor() # try: # # 清空表,初始化測試環(huán)境 # cursor.execute('delete from T2') # except (dmPython.Error, Exception) as err: # print(err) try: # 插入數(shù)據 # cursor.execute("insert into DMHR.EMPLOYEE (EMPLOYEE_ID,EMPLOYEE_NAME,EMAIL,HIRE_DATE,JOB_ID) values(1157, '馬云','888888888@qq.com','2023-05-12','42')") # print('python: insert success!') # # 更新數(shù)據 # cursor.execute("update DMHR.EMPLOYEE set EMPLOYEE_NAME = '劉強東' where EMPLOYEE_ID = 1157") # print('python: update success!') # 查詢數(shù)據 cursor.execute("select id from test.SYSTEMS_USER") res = cursor.fetchall() for tmp in res: for c1 in tmp: print(c1) print('python: select success!') # # 刪除數(shù)據 # cursor.execute("delete from DMHR.EMPLOYEE where EMPLOYEE_ID = 1157") # print('python: delete success!') # except (dmPython.Error, Exception) as err1: print(err1) conn.close() except (dmPython.Error, Exception) as err: print(err)
到此這篇關于Python連接達夢數(shù)據庫的實現(xiàn)示例的文章就介紹到這了,更多相關Python連接達夢數(shù)據庫內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
在Python開發(fā)環(huán)境中調用ChatGPT模型詳細過程
在開發(fā)過程當中時常需要使用 ChatGPT 來完成一些任務,但總是使用網頁交互模式去 Web 端訪問 ChatGPT 是很麻煩的,這時候我們可以使用代碼來調用 ChatGPT 模型,本文將詳細介紹在 Python 開發(fā)環(huán)境中調用 ChatGPT 模型過程,,需要的朋友可以參考下2023-05-05python 實現(xiàn)對數(shù)據集的歸一化的方法(0-1之間)
今天小編就為大家分享一篇python 實現(xiàn)對數(shù)據集的歸一化的方法(0-1之間),具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-07-07解決導入django_filters不成功問題No module named ''django_filter''
這篇文章主要介紹了解決導入django_filters不成功問題No module named 'django_filter',具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-07-07