forked from Xu-Guo/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsert2.py
More file actions
36 lines (26 loc) · 984 Bytes
/
Copy pathinsert2.py
File metadata and controls
36 lines (26 loc) · 984 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/python
# -*- coding: utf-8 -*-
import MySQLdb as mdb
import sys
try:
con = mdb.connect('localhost', 'root', '355itu11', 'test')
cur = con.cursor()
# cur.execute("DROP TABLE IF EXISTS Writers")
# cur.execute("CREATE TABLE Writers(Id INT PRIMARY KEY AUTO_INCREMENT, \
# Name VARCHAR(25)) ENGINE=INNODB")
cur.execute("INSERT INTO Writers(Name) VALUES('Jack London')")
cur.execute("INSERT INTO Writers(Name) VALUES('Honore de Balzac')")
cur.execute("INSERT INTO Writers(Name) VALUES('Lion Feuchtwanger')")
cur.execute("INSERT INTO Writers(Name) VALUES('Emile Zola')")
cur.execute("INSERT INTO Writers(Name) VALUES('Truman Capote')")
cur.execute("INSERT INTO Writers(Name) VALUES('Terry Pratchett')")
con.commit()
except mdb.Error, e:
print "this is mdb Error"
if con:
con.rollback()
print "Error %d: %s" % (e.args[0], e.args[1])
sys.exit(1)
finally:
if con:
con.close()