#!/usr/bin/python
# -*- coding: utf-8 -*-
import pymysql def fileDB():
# 打开数据库连接(ip/数据库用户名/登录密码/数据库名)
db = pymysql.connect("192.168.10.42", "用户名", "密码", "数据库名称")
# 使用 cursor() 方法创建一个游标对象 cursor
# 使用cursor()方法获取操作游标
cursor = db.cursor() # 使用execute方法执行SQL语句
cursor.execute("SELECT tx_id FROM tx_record_attchment GROUP BY tx_id HAVING (count(tx_id)<4) ORDER BY create_time DESC") # 使用 fetchone() 方法获取一条数据
txId = cursor.fetchone() print "txId : %s " % txId[0]
print "txId[0][0] : %s " % type(txId[0])
cursor.execute("SELECT enterprise_tx_no FROM tx_record WHERE id="+str(txId[0])) # 使用 fetchone() 方法获取一条数据
txNo = cursor.fetchone()
print "Database version : %s " % txNo # 关闭数据库连接
db.close()
return txNo[0]
#fileDB()

python连接数据库--查询数据的更多相关文章

  1. java JDBC 连接数据库查询数据与直接使用sql的疑问

    JDBC 封装连接是好的前提: SystemAuthorizingRealm c = new SystemAuthorizingRealm(); conn = c.getConnection(); / ...

  2. AJAX服务器返回数据 连接数据库查询数据

    getcustomer.asp" 中的源代码负责对数据库进行查询,然后用 HTML 表格返回结果: <% response.expires=-1 sql="SELECT * ...

  3. spring boot 项目连接数据库查询数据过程

    spring boot 项目搭建 pom.xml <?xml version="1.0" encoding="UTF-8"?> <projec ...

  4. springMVC框架连接数据库查询数据

    1.框架搭建,创建一个maven项目打war包 web.xml文件 <?xml version="1.0" encoding="UTF-8"?> & ...

  5. python连接数据库查询

    import sqlite3 as db conn = db.connect(r'D:/data/test.db') print ('Opend database successfully \n') ...

  6. python 连接数据库,查询结果写入数据到excel

    使用Python链接数据库查询数据,并将查询结果写入到Excel中,实现方法上主要有两步,第一,查数据,第二,写Excel. 一.导入需要的包 import time import xlwt from ...

  7. 吴裕雄--天生自然python数据清洗与数据可视化:MYSQL、MongoDB数据库连接与查询、爬取天猫连衣裙数据保存到MongoDB

    本博文使用的数据库是MySQL和MongoDB数据库.安装MySQL可以参照我的这篇博文:https://www.cnblogs.com/tszr/p/12112777.html 其中操作Mysql使 ...

  8. Python连接Oracle数据查询导出结果

    python连接oracle,需用用到模块cx_oracle,可以直接pip安装,如网络不好,可下载离线后本地安装 cx_oracle项目地址:https://pypi.org/project/cx_ ...

  9. Python MySQL - 进行数据查询

    #coding=utf-8 import mysql.connector import importlib import sys # reload(sys) # sys.setdefaultencod ...

随机推荐

  1. redis3.2.11 安装

    wget http://download.redis.io/releases/redis-3.2.11.tar.gz [root@hdp01 src]# .tar.gz -C /opt/ [root@ ...

  2. webrtc 术语

    参考网址 https://webrtcglossary.com/ ORTC stands for Object-RTC.ORTC is an initiative involving Google, ...

  3. django1.7+nginx1.4.4的static配置

    静态文件指像css,js,images之类的文件. 1.工程配置setting.py STATIC_URL = /static/ STATIC_ROOT = /home/www/winingcpi/s ...

  4. htmlunit 自动化提交/获取网页数据,自动化测试

    开源组件: https://sourceforge.net/projects/htmlunit/ demo public void post() { try { WebClient client = ...

  5. java代码异常处理篇-----循环

    总结:注意一个方法:nextLine();它表示:执行当前行,返回跳过的输入信息. package com.da; import java.util.InputMismatchException; i ...

  6. RabbitMQ介绍

    (一)RabbitMQ基本概念 RabbitMQ是流行的开源消息队列系统,用erlang语言开发.我曾经对这门语言挺有兴趣,学过一段时间,后来没坚持.RabbitMQ是 AMQP(高级消息队列协议)的 ...

  7. 侯捷STL学习(十)--容器hashtable探索(unordered set/map)

    layout: post title: 侯捷STL学习(十) date: 2017-07-23 tag: 侯捷STL --- 第二十三节 容器hashtable探索 hashtable冲突(碰撞)处理 ...

  8. C# Dynamic通用反序列化Json类型并遍历属性比较

    背景 : 最近在做JAVA 3D API重写,重写的结果需要与原有的API结果进行比较,只有结果一致时才能说明接口是等价重写的,为此需要做一个API结果比较的工具,比较的内容就是Json内容,但是为了 ...

  9. src路径

  10. 解决CentOS遇到Qt编译(error: cannot find -lGL)

    笔者CentOS 6.5 64位,安装完成Qt5.5.1.随意新建一个Qt Widgets Application. 结果遇到Qt编译问题,提示信息如下: error: cannot find -lG ...