首页 > 数据库 >python 连接数据库

python 连接数据库

时间:2023-04-27 18:14:58浏览次数:44  
标签:cus python 数据库 flow cursor rate trans 连接

使用pymysql连接数据库

import pymysql
conn = pymysql.connect(
    host="10.00.0.00",
    port=31379,
    user="root",
    password="123456",
    database="acc_test"
)
 # 模拟从数据库获取单个字段值
with conn.cursor() as cursor:
    # 获取【不良率】
    sql1 = "SELECT trans_amount  FROM  acc_cus.cus_repay_trans_flow WHERE project_no = 'BUWS10043190001' AND flow_sn = '1296240919574950115'"
    cursor.execute(sql1)
    result1 = cursor.fetchall()
    defective_rate = str(result1[0][0])
    defective_rate_num = int(result1[0][0])
    # 获取【年利率】
    sql2 = "SELECT trans_amount  FROM  acc_cus.cus_repay_trans_flow WHERE project_no = 'BUWS10043190001' AND flow_sn = '1296240919574950116'"
    cursor.execute(sql2)
    result2 = cursor.fetchall()
    year_rate = str(result2[0][0])
    year_rate_num = int(result2[0][0])
	
# 关闭数据库连接    
conn.close()

标签:cus,python,数据库,flow,cursor,rate,trans,连接
From: https://www.cnblogs.com/Uni-Hoang/p/17359857.html

相关文章

  • Python-集合的基本操作(set)
    1. 前言python中的集合和数学里的类似也是用于存放不重复的元素,它有可变集合(set)和不可变集合(feozenset)两种,集合的所有元素都放在一对大括号"{}"里(列表是[]、元组是()、字典是{}),集合最好的应用就是去重,因为集合中的每一个元素都是唯一的。 2. 集合的创建2.1.直接使用"{}"创......
  • python-docx设置docx文档表格样式
    使用python-docx,设置docx文档第4行表格第3行第2列单元格的字体对齐方式、加粗fromdocximportDocumentfromdocx.enum.textimportWD_ALIGN_PARAGRAPH#加载Word文档doc=Document('example.docx')#获取表格并定位到指定单元格table=doc.tables[3]cell=table.ce......
  • spring boot jpa MYSQL教程mysql连接的空闲时间超过8小时后 MySQL自动断开该连接
     SunApr1608:15:36CST2023Therewasanunexpectederror(type=InternalServerError,status=500).PreparedStatementCallback;SQL[selectuserIdfromfamilyxiao_UserConnectionwhereproviderId=?andproviderUserId=?];Nooperationsallowedaftercon......
  • Linux-Centos 用crontab定时运行python脚本详细步骤
    服务器总是要定时运行某个程序,而我在解决这个问题的时候遇到很多困难,特此记录下来。1.编辑crontab配置crontab-e服务器一般会安装好crontab,若没有安装请按命令安装yuminstallcrontabs2.编写配置文件当打开配置文件的时候,我们可以看到类似的配置代码。每一行都代表一个......
  • Python-字典的基本操作
    1.字典的创建1.1、直接赋值创建字典语法格式:变量名={键1:值1,键2:值2,...}info={'第一个':0,"第二个":1,"第三个":2}print(info)1.2、使用内置函数dict()创建字典内置函数dict()可通过其他字典、“(键,值)”对的序列或关键字参数来创建字典。#创建空的字典info2=dict()#使......
  • Python MatplotlibDeprecationWarning Matplotlib 3.6 and will be removed two minor
    在Pycharm中使用Matplotlib中的pyplot时,运行代码报错:MatplotlibDeprecationWarning:SupportforFigureCanvaseswithoutarequired_interactive_frameworkattributewasdeprecatedinMatplotlib3.6andwillberemovedtwominorreleaseslater.解决方法File->Set......
  • c# winform Socket多文件传输并把传输文件保存到Oracle数据库Blob字段里
    服务器接收端代码:usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.Net;usingSystem.Threading;usingSystem.......
  • 查询出数据库中char型字段的最大值,查出数据库中字段最大值,max,缺少列,xh...
    SELECTmax(cast(xhasint))asxhFROMkk.kkcltj用cast(xhasint)把varchar(2)的类型转成int后再查出最大值注意:xh的字段里只能存储char型或number型数据,否则会报无效符号错误有时候不主意会写成SELECTmax(cast(xhasint))FROMkk.kkcltj这样select出来的值就没有......
  • Python中的运算符与优先级
    算术运算符这里仅列出与c++语法不一致的内容。指数a**b取模a%%b整除a//b比较运算符与c++语法完全相同,用于判断两个变量、常量或者表达式之间的大小,比较运算的结果是布尔类型。逻辑运算符与c++语法完全相同,对布尔型的常量、变量或表达式进行运算,逻辑运算的......
  • Python的OS模块分析文件路径层次信息——获取文件路径、全名(文件名+尾缀)
    Code:importosFilePath="/a/bb/ccc/dddd.png"FolderPath,FullFileName=os.path.split(FilePath)Name,Suffix=os.path.splitext(FullFileName)print("文件路径:{}\n文件全名:{}\n文件名:{}\n文件后缀:{}".format(FolderPath,FullFileName,Name,......