一、安装dmPython

在这里插入图片描述
添加环境变量

[root@localhost dmPython]# vim ~/.bash_profile 
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/dm8/bin"
export DM_HOME="/dm8"
[root@localhost dmPython]# source  ~/.bash_profile 

安装dmPython

[root@localhost dmPython]# python setup.py install

二、测试

1.创建python测试脚本

[root@localhost dmPython]# vim ConnDM.py
import dmPython
try:
  conn = dmPython.connect(user='SYSDBA', password='szoscar55@', server='localhost', port=5237)
  cursor = conn.cursor()
  print('python: conn success!')
  conn.close()
except (dmPython.Error, Exception) as err:
  print(err)

问题:

2.执行脚本

代码如下(示例):

[root@localhost dmPython]# python ConnDM.py

在这里插入图片描述

三、建表测试

[root@localhost dmPython]# vim connPython2.py
import dmPython

try:
   conn = dmPython.connect(user='SYSDBA', password='szoscar55@', server='localhost', port=5237)
   cursor = conn.cursor()
   print('python: conn success!')
   cursor.execute("create table test5(c1 int, c2 varchar)")
   cursor.execute("insert into test5 values(2,'yhy')")
   cursor.execute("select * from test5")
   res = cursor.fetchall()
   for tmp in res:
     for c1 in tmp:
       print(c1)
       print('python: select success!')
       conn.close()
except (dmPython.Error, Exception) as err:
  print(err)

在这里插入图片描述

问题总结

1.代码缩进问题
在这里插入图片描述
解决:
该行代码没有缩进,添加空格缩进就可以了

达梦技术社区:https://eco.dameng.com

Logo

DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。

更多推荐