Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import mysql.connector
- user = 'root';
- password = 'root';
- cnx = mysql.connector.connect(user=user, password=password,
- host='127.0.0.1',
- database='cs360')
- cursor = cnx.cursor();
- dropTable = "DROP TABLE IF EXISTS Employee";
- cursor.execute(dropTable);
- employee = "CREATE TABLE Employee (Id INT NOT NULL AUTO_INCREMENT,Name VARCHAR(200),Salary INT,DepartmentId INT,PRIMARY KEY (Id))";
- cursor.execute(employee);
- addEmployee = "INSERT INTO Employee (Name, Salary, DepartmentId) VALUES (%s, %s, %s)";
- dataEmployee = [('Joe', 70000, 1), ('Henry', 80000, 2)];
- cursor.executemany(addEmployee, dataEmployee);
- query = ("select * from Employee");
- cursor.execute(query);
- for (Id, Name, Salary, DepartmentId) in cursor:
- print Id, Name, Salary, DepartmentId
- cnx.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement