IronPython连接MySQL的方法步骤
作者:zx 时间:2024-01-27 05:43:05
原以为在IronPython中使用MySQL是一件很容易的事情,即使有麻烦,也可以改变路径,加载Python下的MySQL模块。事实证明,这是我一厢情愿的想法。要想在IronPython中连接MySQL数据库,必须要调用MySql.Data动态库——这个dll很容易在网上找到,但如何使用这个库,网上的资料如凤毛麟角,难觅其踪。好不容易找到几篇,却又语焉不详,不知所云。
经过好一番折腾,终于搞明白了MySql.Data.dll的用法。
1. 导入模块
import clr
clr.AddReference("MySql.Data.dll")
from MySql.Data.MySqlClient import *
2. 连接数据库
conStr = 'server=%s; user id=%s; password=%s; database=%s; pooling=false; charset=gbk' % (host, user, passwd, db)
db = MySqlConnection(conStr)
db.Open()
3. 执行插入(更新、删除等)操作
sqlStr = "INSERT INTO ..."
cmd = MySqlCommand(sqlStr, db)
rows = cmd.ExecuteNonQuery()
4. 执行查询语句
cmd = self.db.CreateCommand ()
cmd.CommandText = "SELECT ..."
r = cmd.ExecuteReader ()
tagList = []
while r.Read ():
tagList.append(r['rfidLabel'])
r.Close ()
return tag in tagList
5. 关闭连接
db.Close ()
怎么样?代码风格是不是感觉有点怪异?
来源:https://blog.csdn.net/xufive/article/details/56009321
标签:IronPython,连接,MySQL
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python爬虫爬取微博评论案例详解
2022-12-23 13:31:53
![](https://img.aspxhome.com/file/2023/7/92497_0s.png)
彻底弄懂Python中的回调函数(callback)
2021-02-26 23:51:57
![](https://img.aspxhome.com/file/2023/8/86148_0s.png)
Python多进程库multiprocessing中进程池Pool类的使用详解
2022-11-22 03:21:11
![](https://img.aspxhome.com/file/2023/6/105456_0s.png)
xhtml+css页面制作过程中问题的解决方案
2008-08-05 18:00:00
wap开发中如何有效的利用缓存减少消息的传送量
2022-12-16 04:23:17
删除PHP数组中头部、尾部、任意元素的实现代码
2023-06-14 12:40:44
![](https://img.aspxhome.com/file/2023/1/55471_0s.png)
Python 实现子类获取父类的类成员方法
2022-01-14 00:28:17
基于python,Matplotlib绘制函数的等高线与三维图像
2021-09-06 08:51:33
![](https://img.aspxhome.com/file/2023/5/110425_0s.png)
Python入门教程(三十三)Python的字符串格式化
2023-04-03 11:58:17
![](https://img.aspxhome.com/file/2023/6/112736_0s.jpg)
常用的三种修改mysql最大连接数的方法
2010-03-09 15:42:00
python+pandas分析nginx日志的实例
2021-03-13 12:51:22
![](https://img.aspxhome.com/file/2023/0/98810_0s.jpg)
微信小程序报错:this.setData is not a function的解决办法
2024-04-19 09:47:17
使用Webpack构建多页面程序的实现步骤
2024-04-23 09:06:27
OpenCV目标检测Meanshif和Camshift算法解析
2022-06-15 21:30:35
![](https://img.aspxhome.com/file/2023/3/121673_0s.jpg)
python基本数据类型练习题
2022-07-21 14:26:26
![](https://img.aspxhome.com/file/2023/6/98996_0s.png)
深入理解Python异常处理的哲学
2023-07-27 06:11:28
Python OpenCV实现鼠标画框效果
2022-03-02 10:45:15
![](https://img.aspxhome.com/file/2023/8/104918_0s.jpg)
php5.3 不支持 session_register() 此函数已启用的解决方法
2023-11-16 01:59:39
python ipset管理 增删白名单的方法
2021-02-10 17:38:19
pandas dataframe添加表格框线输出的方法
2021-11-28 01:34:41
![](https://img.aspxhome.com/file/2023/8/118548_0s.jpg)