Writing to a Database,writingtodatabase,import MySQL
Writing to a Database,writingtodatabase,import MySQL
import MySQLdbdb= MySQLdb.connect(host='localhost', user='python-test', passwd='python',db='python-test')try: title = raw_input('Please enter a book title: ') if title == '' : exit author = raw_input('Please enter the author's name: ') pubdate = int( raw_input('Enter the publication year: ') )except: print 'Invalid value' exitprint 'Title: [' + title + ']'print 'Author: ['+ author + ']'print 'Publication Date: ' + str(pubdate)cursor = db.cursor()stmt = 'INSERT INTO Books (BookName, BookAuthor, PublicationDate) VALUES (''stmt = stmt + titlestmt = stmt + '', ''stmt = stmt + authorstmt = stmt + '', 'stmt = stmt + str(pubdate)stmt = stmt + ')'cursor.execute(stmt)print 'Record added!'cursor.close ()db.commit ()
- Searching Lists,searchinglists,li = ['a', '
- tell(): Returns the current file position,returnsposit
- Tools for Working with Lists,workinglists,# The array
- Garbage collector is enabled,garbagecollector,import g
- locale module accesses a database of culture specific da
- Bind mouse click action to the object on a canvas,bind
热门文章:
相关内容
- Searching Lists,searchinglists,li = ['a', '
- tell(): Returns the current file position,returnsposition,f = open(
- Tools for Working with Lists,workinglists,# The array
- Garbage collector is enabled,garbagecollector,import gcgc_
- locale module accesses a database of culture specific data formats,
- Bind mouse click action to the object on a canvas,bindcanvas,from T
- Math: sin,mathsin,import mathp
- Radiobuttons demonstration set Font in Text,,from Tkinter
- Storing Non-ASCII Characters,storingnon-ascii,s = u'La Pe\
- List Comprehensions in buildConnectionString, Step by Step,,params
评论关闭