簡體   English   中英

在Python中的SQLite數據庫連接期間引發異常

[英]Raising exception during SQLite database connection in Python

這是我的代碼段:

import sqlite3
database = "sample.db"
def dbConnection(database):
    try:
        connection = sqlite3.connect(database)
        db_cursor = connection.cursor()
        db_cursor.execute("show tables;")
        rows = db_cursor.fetchall()
        for row in rows:
            print row
        connection.close()
    except sqlite3.Error, e:
        print "Error in connection",e
dbConnection("enb.db")

它引發了這個異常:

Error in connection near "show": syntax error

我看不到語法有什么問題,因為我只想查看數據庫中的表。 這可能是什么問題?

SQLite不支持“ SHOW TABLES”。 它對其他數據庫(例如MySQL)有效。

SQLite SQL參考

如何在SQLite中“顯示表”

SQLite不支持“顯示”功能。 您可以SELECT name FROM sqlite_master where type='table'使用SELECT name FROM sqlite_master where type='table' 我是從這個線程( Android sqlite顯示表)中找到的

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM