zoukankan      html  css  js  c++  java
  • python连接数据库--查询数据

     1 #!/usr/bin/python
     2 # -*- coding: utf-8 -*-
     3 import pymysql
     4 
     5 def fileDB():
     6         # 打开数据库连接(ip/数据库用户名/登录密码/数据库名)
     7         db = pymysql.connect("192.168.10.42", "用户名", "密码", "数据库名称")
     8         # 使用 cursor() 方法创建一个游标对象 cursor
     9         # 使用cursor()方法获取操作游标
    10         cursor = db.cursor()
    11 
    12         # 使用execute方法执行SQL语句
    13         cursor.execute("SELECT tx_id FROM tx_record_attchment  GROUP BY tx_id HAVING (count(tx_id)<4)  ORDER BY  create_time  DESC")
    14 
    15         # 使用 fetchone() 方法获取一条数据
    16         txId = cursor.fetchone()
    17 
    18         print "txId : %s " % txId[0]
    19         print "txId[0][0] : %s " % type(txId[0])
    20         cursor.execute("SELECT enterprise_tx_no FROM tx_record  WHERE  id="+str(txId[0]))
    21 
    22         # 使用 fetchone() 方法获取一条数据
    23         txNo = cursor.fetchone()
    24         print "Database version : %s " % txNo
    25 
    26         # 关闭数据库连接
    27         db.close()
    28         return txNo[0]
    29 #fileDB()
  • 相关阅读:
    5. 添加后台管理页面
    4. 整合MyBatis
    3. 添加多个控制器
    2. 引入springmvc
    1. 开篇-springboot环境搭建
    去除angularjs路由的显眼的#号
    EasyUI DataGrid 分页实现示例
    等待对话框实现
    使用Struts2搭建登录注册示例
    观察者模式
  • 原文地址:https://www.cnblogs.com/wangxiaoqun/p/9045112.html
Copyright © 2011-2022 走看看