title: python sqlite3 insert table error: cursor is not connected?
body: <p>I try to use <code>sqlite3</code> to import data to a table <code>babyName</code> in my AWS RDS database. For the two methods I tried, the first one <code>data_entry()</code> works fine every time but the second <code>new_data_entry()</code> gave me </p>
  
  <blockquote>
    <p>Cursor is not connected </p>
  </blockquote>
  
  <p>or </p>
  
  <blockquote>
    <p>Not all parameters are used </p>
  </blockquote>
  
  <p>error. Could you please help me?</p>
  
  <pre><code>import mysql.connector
  from mysql.connector import errorcode
  
  # start connection
  try:
      cnn = mysql.connector.connect(
      user = '*****',
      password = '*****',
      host = '*****-mysql.*****.us-****-1.rds.amazonaws.com',
      database = '*******')
      print('It works!')
  except mysql.connector.Error as e:
      if e.errno == errorcode.ER_ACCESS_DENIED_ERROR:
          print('Somethign is wrong with username or password')
      elif e.errno == errorcode.ER_BAD_DB_ERROR:
          print('Database does not exist')
      else:
          print(e)
  
  # start cursor
  import sqlite3
  c = cnn.cursor()
  def creat_table():
      c.execute("CREATE TABLE IF NOT EXISTS babyName (name TEXT, gender TEXT, frequency INTEGER, year TEXT)")
  def data_entry():
      c.execute("INSERT INTO babyName VALUES ('Mary', 'F', 1234, '2008')")
      cnn.commit()
      c.close()
      cnn.close()
  
  def new_data_entry():
      name = 'Wendy'
      gender = 'F'
      frequency = 321
      year = '2006'
      c.execute("INSERT INTO babyName (name, gender, frequency, year) VALUES (?, ?, ?, ?)", (name, gender, frequency, year))
      cnn.commit()
      c.close()
      cnn.close()
  
  # creat_table()
  data_entry()
  print('It works!')
  new_data_entry()
  </code></pre>
  
  <p>The error message I kept getting:</p>
  
  <pre><code>It works!
  It works!
  Traceback (most recent call last):
    File "/Users/*****/sqlite3_python_cc.py", line 53, in &lt;module&gt;
      new_data_entry()
    File "/Users/*****/sqlite3_python_cc.py", line 45, in new_data_entry
      c.execute("INSERT INTO babyName (name, gender, frequency, year) VALUES (?, ?, ?, ?)", values)
    File "/Users/*****/anaconda/lib/python3.6/site-packages/mysql/connector/cursor.py", line 529, in execute
      raise errors.ProgrammingError("Cursor is not connected")
  mysql.connector.errors.ProgrammingError: Cursor is not connected
  </code></pre>