//모듈 import
import sqlite3

//버전 확인
sqlite3.version
Out[2]: '2.6.0'
sqlite3.sqlite_version
Out[3]: '3.31.1'

//connect DB 생성
con=sqlite3.connect("/Users/mhy/test/kospi.db")
type(con)
Out[5]: sqlite3.Connection

//cursor 객체 생성
cursor = con.cursor()

//테이블 생성
cursor.execute("CREATE TABLE kakao(Date text, Open int, High int, Low int, Closing int, Volumn int)")
Out[9]: <sqlite3.Cursor at 0x106df9d50>

//테이블에 데이터 넣기
cursor.execute("INSERT INTO kakao VALUES('16.06.03', 9700, 98600, 96900, 9800, 321405)")
Out[11]: <sqlite3.Cursor at 0x106df9d50>
cursor.execute("INSERT INTO kakao VALUES('16.06.02', 99000, 99300, 96300, 97500, 556790)")
Out[12]: <sqlite3.Cursor at 0x106df9d50>

//커밋 및 종료
con.commit()
con.close()

+ Recent posts