Page 94 - PYTHON-12
P. 94

except:


                      db1.rollback()

                   db1.close()


















                           Fetching all the records from EMP table having salary more than 70000.

                   import MySQLdb


                   db1 = MySQLdb.connect("localhost","root","","TESTDB" )

                   cursor = db1.cursor()

                   sql = "SELECT * FROM EMP WHERE SALARY > 70000;"


                   try:

                        cursor.execute(sql)

                        #using fetchall() function to fetch all records from the table EMP and store in
                   resultset


                        resultset = cursor.fetchall()

                   for row in resultset:




                         print (row)

                   except:


                      print ("Error: unable to fetch data")

                   db1.close()
   89   90   91   92   93   94   95   96   97   98   99