解決未能為資料庫 ‘資料庫名‘ 中的物件 ‘資料庫日誌檔案‘ 分配空間,因為檔案組 ‘PRIMARY‘ 已滿
安裝navicat,新建school資料庫,並建student(學號 int,姓名 Text,年齡 int)表,插入3個人,程式碼實現。 我的答案: import sqlite3 con=sqlite3.connect("D:\\sql\\SQL1\\test.db3") a=con.cursor() # a.execute(''' # CREATE TABLE COMPANY # (NUM INT PRIMARY KEY NOT NULL, # NAME TEXT NOT NULL, # AGE INT NOT NULL # ) # ''') a.execute(''' INSERT INTO COMPANY(NUM,NAME ,AGE) VALUES (1,'小明',20) ''') con.commit() con.close()
將以下的000001.csv所有內容寫入到zhengquan.db3資料庫的date表中。
我的答案:
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import sqlite3
b=pd.read_excel("D:\\Project\\19jx2\\000001.xlsx",sheet_name=0)
con=sqlite3.connect("D:\\sql\\zhengquan4.db3")
a=con.cursor()
# a.execute('''
#
# CREATE TABLE COMPANY
#
# ("日期" TEXT PRIMARY KEY ,
# "股票程式碼" TEXT ,
# "名稱" TEXT ,
# "收盤價" TEXT ,
# "最高價" TEXT ,
# "最低價" TEXT ,
# "開盤價" TEXT ,
# "前收盤" TEXT ,
# "漲跌額" TEXT ,
# "漲跌幅" TEXT ,
# "成交量" TEXT ,
# "成交金額" TEXT
# )
#
# ''')
for i in b.iterrows():
a.execute('''
INSERT INTO COMPANY('日期','股票程式碼' ,'名稱','收盤價','最高價','最低價','開盤價','前收盤','漲跌額','漲跌幅','成交量','成交金額')
VALUES ("%s","%s","%s","%s","%s","%s","%s","%s","%s","%s","%s","%s")
'''%(i[1]['日期'],i[1]['股票程式碼'] ,i[1]['名稱'],i[1]['收盤價'],i[1]['最高價'],i[1]['最低價'],i[1]['開盤價'],i[1]['前收盤'],i[1]['漲跌額'],i[1]['漲跌幅'],i[1]['成交量'],i[1]['成交金額']))
con.commit()
con.close()