-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelectQuery.py
More file actions
49 lines (35 loc) · 1.02 KB
/
Copy pathSelectQuery.py
File metadata and controls
49 lines (35 loc) · 1.02 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
'''
Created on Feb 11, 2016
@author: sumkuma2
'''
import MySQLdb
from DBUtil import DbUtil
#dbhost='localhost'
#dbname='pythondb'
#dbuser='root'
#dbpwd='root'
#dbutil = DbUtil(dbhost,dbuser,dbpwd,dbname)
dbutil = DbUtil()
con = dbutil.getMySQLConnection()
cursor = con.cursor()
try:
sql = "SELECT * FROM employee"
cursor.execute(sql)
'''Fetch all the rows in a list of lists.'''
results = cursor.fetchall()
print "empid,first_name,last_name,age,sex,income"
for row in results:
empid = row[0]
fname = row[1]
lname = row[2]
age = row[3]
sex = row[4]
income = row[5]
# Now print fetched result
print empid,",",fname,",",lname,",",age,",",sex,",",income
#print "empid=%d,fname=%s,lname=%s,age=%d,sex=%s,income=%d"%(empid,fname,lname,age,sex,income)
except MySQLdb.Error, e:
print "Error: unable to fecth data %s",e
finally:
cursor.close()
con.close()