Question

In: Computer Science

Using Python, write a segment of code to populate the table "employee" of the database "EmployeeDB”...

Using Python, write a segment of code to populate the table "employee" of the database "EmployeeDB” with the data below. Import your choice of DB connector (import MySQLdb/sqlite3…)

Create the“employee” table with schema = [name, address, age]

Insert this employee: John Doe, 7001 E Williams Field, 32

Solutions

Expert Solution

Answer

here is your python code , if you have any doubt please comment. I am here to help you.

Here i used python3,sqlite3 and jupyter notebook as my editor.

Here is your code

import sqlite3
from sqlite3 import Error


def make_connection(db_name):
    conn = None
    try:
        conn = sqlite3.connect(db_name)
        return conn
    except Error as e:
        print(e)

    return conn
def create_table(conn, create_table_sql):
    try:
        #reate a Cursor object by calling the cursor() method of the Connection object
        c = conn.cursor()
        #executing query
        c.execute(create_table_sql)
    except Error as e:
        print(e)
def insert_table(conn,in_table):
    sql = ''' INSERT INTO employee(name,address,age)
              VALUES(?,?,?) '''
    try:
        #reate a Cursor object by calling the cursor() method of the Connection object
        cur = conn.cursor()
        #execute query with our parameters.
        cur.execute(sql, in_table)
        #If you don't call this method, anything you did since the last call to commit() is not visible from other database connections.
        conn.commit()
    except Error as e:
        print(e)


def main():
    #database name
    database = r"EmployeeDB.db"
    #created a query string for creating table employee in EmployeeDB
    cr_table= """ CREATE TABLE IF NOT EXISTS employee (
                                        name text NOT NULL,
                                        address text,
                                        age number
                                    ); """
    #data for insert the employee table
    data_1 = ('John Doe', '7001 E Williams Field', 32)
    # create a database connection
    conn = make_connection(database)

    # create tables and insert data
    if conn is not None:
        create_table(conn, cr_table)
        insert_table(conn,data_1)
    else:
        print("Error! cannot create the database connection.")


if __name__ == '__main__':
    main()

output

Providing here jupyter notebook screenshot,because you may meet any indentation error refer this image too

Any doubt please comment

Thanks in advance


Related Solutions

Important: please use python. Using while loop, write python code to print the times table (from...
Important: please use python. Using while loop, write python code to print the times table (from 0 to 20, incremented by 2) for number 5. Add asterisks (****) so the output looks exactly as shown below.   Please send the code and the output of the program. ****************************************************************** This Program Shows Times Table for Number 5 (from 0 to 20) Incremented by 2 * ****************************************************************** 0 x 5 = 0 2 x 5 = 10 4 x 5 = 20 6...
Write the DML code to add the first row of each table to the database.
Write the DML code to add the first row of each table to the database.
Database Systems Lab Exercises Populate the Dept table with the following: Dept_Code Dept_Name ICS Information and...
Database Systems Lab Exercises Populate the Dept table with the following: Dept_Code Dept_Name ICS Information and Computer Science COE Computer Engineering SWE Software Engineering SE System Engineering Populate the Faculty table with the following: Faculty_Id Last_Name First_Name Dept 100234 Hashim Ahmad ICS 287234 Yoesuf Mohammed COE 767636 Amn Faisal ICS 557899 Hamzah Yusuf SE 345256 Lukman Mousa SWE 626277 Ali Isa COE 246266 Dawood Ageel SE Change the last name of Faculty Id = 767636 to "Ameen". Change the Dept...
For these of string functions, write the code for it in C++ or Python (without using...
For these of string functions, write the code for it in C++ or Python (without using any of thatlanguage's built-in functions) You may assume there is a function to convert Small string into the language string type and a function to convert your language's string type back to Small string type. 1. int [] searchA,ll(string in...str, string sub): returns an array of positions of sub in in...str or an one element array with -1 if sub doesn't exist in in...str
Using python as the coding language please write the code for the following problem. Write a...
Using python as the coding language please write the code for the following problem. Write a function called provenance that takes two string arguments and returns another string depending on the values of the arguments according to the table below. This function is based on the geologic practice of determining the distance of a sedimentary rock from the source of its component grains by grain size and smoothness. First Argument Value Second Argument Value Return Value "coarse" "rounded" "intermediate" "coarse"...
"PYTHON" Write some code " USING PYTHON" to keep reading numbers from the user until the...
"PYTHON" Write some code " USING PYTHON" to keep reading numbers from the user until the users enters a negative number. The program then prints out: a) the sum of all the numbers b) the average of all the numbers c) the max of the numbers d) the min of the numbers Note we did not cover lists (array) so you will not use them in this problem. Finally, ask the user for their name, then print their name as...
(Python) a) Using the the code below write a function that takes the list xs as...
(Python) a) Using the the code below write a function that takes the list xs as input, divides it into nss = ns/nrs chunks (where nrs is an integer input parameter), computes the mean and standard deviation s (square root of the variance) of the numbers in each chunk and saves them in two lists of length nss and return these upon finishing. Hint: list slicing capabilities can be useful in implementing this function. from random import random as rnd...
Write a verilog code for digital clock and display it’s seven segment using fpga?
Write a verilog code for digital clock and display it’s seven segment using fpga?
Write CREATE TABLE and INSERT INTO statements in order to create and populate five tables in...
Write CREATE TABLE and INSERT INTO statements in order to create and populate five tables in Oracle’s SQL*Plus.The information you need about the database ARE IN THE CHARTS BELOW. Each worksheet includes the following information about its associated table: ➢ Column names (for example, the jr_order table contains the orderID, customerID, orderDate, orderStatus, and orderShippedDate columns); ➢ Column data types (for example, orderID is INT, orderStatus is VARCHAR2(2), etc.); ➢ Column constraints, if any (for example, orderID in the jr_order...
Write a python program per the following specifications: 1. Populate an array(list) of size n =...
Write a python program per the following specifications: 1. Populate an array(list) of size n = 50 randomly with only integers 0 and 1 2. Repeat step 1 nn = 1000 times using either a while loop or a for loop see below At this point you should have a total of 50000 observations with either 0 or 1 This is our experimental data which we will compare to the theoretical expected result From Lab06template.py import random temp = -1...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT