Question

Write a python program on windows which can add data to a my sql database

Write a python program on windows which can add data to a my sql database
0 0
Add a comment Improve this question Transcribed image text
Answer #1

First of all, my sql should be installed on your computer.

Code to add data to a my sql database:

import mysql.connector # Library to import

mydb = mysql.connector.connect(
host="localhost",
  user="yourusername",
passwd="yourpassword",
database="mydatabase"
) # mydb variable which will be used in the program

mycursor = mydb.cursor() # cursor

sql = "INSERT INTO customers (name, address) VALUES (%s, %s)"  
val = ("John", "Highway 21")
mycursor.execute(sql, val) # execute command is that whcih executes your sql queries

mydb.commit() # Commit changes on your database

print(mycursor.rowcount, "record inserted.")

Add a comment
Know the answer?
Add Answer to:
Write a python program on windows which can add data to a my sql database
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Hello, I'm working on inserting data into a table using MySQL and Python on my Windows...

    Hello, I'm working on inserting data into a table using MySQL and Python on my Windows OS laptop; and I am asked to modify the script so that it executes an insert query in one of my database tables. I am also asked to print the table before and after I execute this query in order to ensure the new information was inserted into the table. I'd like to INSERT INTO my EMPLOYEE table. The columns are employee_id, employee_password, order_id...

  • write a sql query to export database data to xml in phpmyadmin.

    write a sql query to export database data to xml in phpmyadmin.

  • Write a python program and pseudocode The Program Using Windows Notepad (or similar program), create a...

    Write a python program and pseudocode The Program Using Windows Notepad (or similar program), create a file called Numbers.txt in your the same folder as your Python program. This file should contain a list on floating point numbers, one on each line. The number should be greater than zero but less than one million. Your program should read the following and display: The number of numbers in the file (i.e. count them) (counter) The maximum number in the file (maximum)...

  • Need help!!! I need two programs that use one common database.. One program using a Visual...

    Need help!!! I need two programs that use one common database.. One program using a Visual Basic windows form using textboxes for data input (first name, last name, phone, email) and it should save the info into an SQL database when a save button is clicked. Second program using a C# windows form that has a drop down menu with all the names that have been saved into the database, when one name is clicked all their information should pop...

  • Please write SQL Query for following questions using Northwind Database: 1. Create a procedure to add...

    Please write SQL Query for following questions using Northwind Database: 1. Create a procedure to add a new record to Territories table. Call it NewTerr. Add the following records using the procedure. TerritoryID        TerritoryDescription     Region 88888 Brooklyn 1 99999 Waco 4 77777 Long Beach 2 2. Create an Update Procedure that will change the Region from 1 to 3 for record with TerritoryID 88888. Call it Update88. 3. Create a Delete Procedure that will delete the one record from...

  • Using oracle sql for creating database nd inserting data I want to write a constraint on...

    Using oracle sql for creating database nd inserting data I want to write a constraint on the date of birth so that any age will be only be from 21 to 60 This constraint should be calculated automatically using sysdate or the system date Hint: data type is date Also for the car year model I want to write a constraint to check that it is not older than 10 years (the field data type is integer) I want it...

  • Consider the following database and answer the questions below. a) Write the SQL statement the displays...

    Consider the following database and answer the questions below. a) Write the SQL statement the displays the names of the students who have enrolled in the Database Systems course b) Write the SQL statement that displays a list of the students whose names start with 'S' c) Write the SQL statement that displays the Student ID, Student Name, Course ID, and Grade for students that passed at least one course with a grade better than B+ (i.e. A-, A, and...

  • QUESTION 1 Match the following: an SQL command that retrieves data A. Communicate B. RETRIEVE C....

    QUESTION 1 Match the following: an SQL command that retrieves data A. Communicate B. RETRIEVE C. exception D. ReadFile E. STORE F. array G. try - catch block H. Connection I. Disconnect0) J. StreamReader K. Respond L. SQL M. Fork N. Query O. BlowUp P. SELECT Q. Close0 R. StreamWriter S. WriteFile T. UPDATE an SQL command that changes data ., class that can be used to read data from a file , establishing communication with a database a method...

  • Write SQL queries to answer the following question: A. Which students are enrolled in Database and...

    Write SQL queries to answer the following question: A. Which students are enrolled in Database and Networking? (Hint: use SectionNo for each class, so that you can determine the answer from the Registration table by itself.) I have attempted the code below, but am receiving an error under the first SELECT, showing error code 1064, (syntax error) SELECT StudentName, StudentID FROM Student WHERE StudentID =(select StudentID FROM Registration WHERE (SectionNo=2714 OR SectionNo=2715) GROUP BY StudentID HAVING COUNT (*)>1;

  • Programming Microsoft Visual Basic 2012/2015 - Create an SQL or Access database with all your friends’...

    Programming Microsoft Visual Basic 2012/2015 - Create an SQL or Access database with all your friends’ information and write a program to load the names in the combo box and also search the database and find your friend’s record off the database by name and retrieve all the information from the database to the form including your friend’s picture. You should be able to add new friends, update an existing friends’ information and delete a friend’s record. See the sample...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT