python - Python插入sqlite表
问题描述
一直说参数的类型不受支持。我究竟做错了什么?我试过 [rows] 和 ,rows)。我在其他两行中遇到的另一个错误是我提供的绑定数量不正确。当前语句使用 9 个,提供了 11 个。
import csv
import sqlite3
#define connection and cursor
conn = sqlite3.connect('metrics1.db')
c = conn.cursor()
#Table Definition
##cmd = 'CREATE TABLE IF NOT EXISTS Metrics(ID INTEGER PRIMARY KEY
AUTOINCREMENT, ticket_num INTEGER, s$
#Creating the Tables
c.execute('''CREATE TABLE IF NOT EXISTS Metrics([ID] INTEGER PRIMARY KEY AUTOINCREMENT, [ticket_num] IN$
#Opening Metrics CSV
file = open('/root/CustomerSurveys.csv')
#Read File
rows = csv.reader(file)
# Importing the contents of the file into metrics table
c.executemany("INSERT INTO metrics values (?,?,?,?,?,?,?,?,?)", [rows])
# SQL query to retrieve all data from
# the person table To verify that the
# data of the csv file has been successfully
# inserted into the table
c.execute("SELECT * FROM metrics1")
print(c.fetchall())
# Output to the console screen
conn.commit()
conn.close()
解决方案
推荐阅读
- javascript - 递归检查一系列操作是否产生给定的数字
- python - Python 等效于 MATLAB 的 deval
- sql - 使用一个带循环的查询将所有空字符串更改为 NULL。SQL
- python - 访问 Python 程序的输出
- matlab - F#中的Matlab“差异”(逐个元素减去)
- digital-signature - 通过 javacard apdu 发送一个字节 []
- json - lua json解析变量
- android - 取消文件上传(改造)从协程kotlin android开始
- java - 当我向 OM2M 发送 CoAP 消息时发生 nullpointerException
- cefsharp - 将上下文参数传递给 ResourceHandler 的最佳方法是什么