Skip to content

Latest commit

 

History

History
37 lines (30 loc) · 894 Bytes

192.md

File metadata and controls

37 lines (30 loc) · 894 Bytes
@author jackzhenguo
@desc
@tag
@version 
@date 2020/03/30

192: 创建SQLite连接

编写一个Python程序,创建一个SQLite数据库,并与数据库连接,打印SQLite数据库的版本

一种解决方法:

import sqlite3
try:
   sqlite_Connection = sqlite3.connect('temp.db')
   conn = sqlite_Connection.cursor()
   print("连接到 SQLite.")
   sqlite_select_Query = "select sqlite_version();"
   conn.execute(sqlite_select_Query)
   record = conn.fetchall()
   print("SQLite 数据库的版本是 ", record)
   conn.close()
except sqlite3.Error as error:
   print("连接到SQLite出错:", error)
finally:
   if (sqlite_Connection):
       sqlite_Connection.close()
       print("关闭SQLite连接")

以上就是第192例,希望对你有用,欢迎点赞支持。

[上一个例子](191.md) [下一个例子](193.md)