晓天蔡
晓天蔡

Reputation: 25

How to display the table in sqlite3 by creating the table via Python

I just used the Pycharm and the package Sqlite3 to generate a table in sqlite3. Meanwhile, I am using SqliteStudio to visualize the relationship between databases and tables. However, the table created from Pycharm cannot be seen in SqliteStudio. Any idea how can I achieve it?

here is the code:

import sqlite3


def conSqlite():
  conn = sqlite3.connect('C:\\Users\jet.cai\Documents\Logsitic.db')

  conn.execute('''CREATE TABLE CNAME
  (ID INT PRIMARY KEY  NOT NULL,
  NAME            TEXT NOT NULL,
  AGE             TEXT NOT NULL)''')

  print('Done')

  cursor = conn.execute("select id from cname")
  for row in cursor:
      print('ID = ', row[0], 'NAME = ', row[1], 'AGE = ', row[2] )


  conSqlite()

Upvotes: 0

Views: 344

Answers (1)

tgrandje
tgrandje

Reputation: 2534

If you want to stay with python, you may find interesting to use pandas.

import pandas as pd
import sqlite3
con = sqlite3.connect('C:\\Users\jet.cai\Documents\Logsitic.db')
df = pd.read_sql_query("select id from cname", con)
print(df)

Upvotes: 3

Related Questions