问题遇到的现象和发生背景 我现在想读取db2数据库里的数据,连接了数据库但是出错。
问题相关代码,请勿粘贴截图 import ibm_db_dbi
import torch
import torch.nn as nn
import pandas as pd
from torch.autograd import Variable
import torch.utils.data as Data
import os
os.environ['KMP_DUPLICATE_LIB_OK'] = 'TRUE'
from flask import Flask, request
from dateutil.parser import parse
connect = ibm_db_dbi.connect("DATABASE=SAMPLE ;HOSTNAME=127.0.0.1;PORT=50000;PROTOCOL=TCPIP;UID=db2admin;PWD=Fjj.12345;", "", "")
获取可以执行SQL的游标
cursor = connect.cursor()
获取训练所需的输入数据
sql = "Select from SAMPLE.NEWTABLE2 where CLOCK between ? and ?"
传参
cursor.execute(sql)
fetchall()函数,它的返回值是多个元组,即返回多个行记录row,如果没有结果,返回的是()
row = cursor.fetchall()