def getConnection(path):
if not os.path.exists(path):
return None
try:
connect = sqlite3.connect(path)
except Exception, e:
print "ConnectSubLibraryDB Error! :%s" % e
return None
return connect
conn = getConnection('xxxxx')#你的db文件路径
cur = conn.cursor()
ret = None
try:
cur.execute(sqlStr)#执行的sql语句
ret = cur.fetchall()
except Exception, e:
print'_execSql Error:[%s], Reason:[%s]'%(sqlStr, e)
ret = None
finally:
cur.close()
conn.close()