直接访问mysql,示例如下:

# coding:utf-8
import time
import MySQLdb
# import traceback
# import sys conn = MySQLdb.connect(host='127.0.0.1', port=3306, user='root', passwd='root', db='dev', charset="utf8", )
cur = conn.cursor()
# cur.execute("SET NAMES utf8") try:
sql = "create table mytest1("
sql = sql + "id int(11) not null auto_increment,"
sql = sql + "channelcode varchar(100) null,"
sql = sql + "systemcode varchar(100) not null,"
sql = sql + "systemname varchar(100) not null,"
sql = sql + "primary key(id))"
print sql;
cur.execute(sql);
except Exception, e:
print Exception, ":", e try:
cur.execute("insert into mytest1(systemcode,systemname) values('test','测试')")
conn.commit()
print 'insert new mytest1.'
except Exception, e:
print Exception, ":", e
# traceback.print_exc()
# except:
# info=sys.exc_info()
# print info[0],":",info[1] try:
cur.execute("update mytest1 set systemname='测试" + time.strftime('%Y-%m-%d %H:%M:%S') + "' where systemcode='test'");
conn.commit()
except Exception, e:
print Exception, ":", e try:
itsystem = cur.execute("select * from mytest1");
print 'count:' + str(itsystem);
info = cur.fetchmany(itsystem)
for ii in info:
# if print ii,chinese string will print it's unicode with u\####
print str(ii[0]) + ',' + (ii[1] == None and str(None) or ii[1]) + ',' + ii[2] + ',' + ii[3]
except Exception, e:
print Exception, ":", e try:
cur.execute("delete from itsystem where systemcode='test'");
conn.commit() cur.execute("drop table mytest1");
except Exception, e:
print Exception, ":", e
cur.close()
conn.close()

最新文章

  1. Fzu2124 - 吃豆人 BFS
  2. 一行css代码调试中学到的javascript知识,很有意思
  3. Slim + Twig 构建PHP Web应用程序
  4. [selenium webdriver Java]元素定位——findElement/findElements
  5. 如何克隆路由器MAC地址,怎么操作?
  6. JS 定時刷新父類頁面
  7. Codeforces 306B
  8. Java Web整合开发(80) -- EJB & WebService
  9. HDU 1695 GCD#容斥原理
  10. CSS BFC(Block Formatting Context)
  11. 数据分析之Pandas
  12. sql注入2
  13. Python_反射
  14. net core体系-web应用程序-4asp.net core2.0 项目实战(1)-2项目说明和源码下载
  15. requests模块的使用
  16. [转]Java反射机制详解
  17. Spring获取bean工具类,可用于在线程里面获取bean
  18. LintCode: Convert Sorted Array to Binary Search Tree With Minimal Height
  19. XSS安全处理
  20. hdu 3874(树状数组)题解

热门文章

  1. django静态文件数据库设置
  2. magento 备份
  3. ios - loadView与viewDidload
  4. dubbo源码分析4-基于netty的dubbo协议的server
  5. Java Servlet(七):JavaWeb MVC 操作(jdk7+tomcat7+eclipse)
  6. 【Unity3D基础】让物体动起来①--UGUI鼠标点击移动
  7. 拼linq 时网上整理的一个类
  8. IOS基础面试题
  9. asp.net MVC实现文章的上一篇下一篇
  10. ASP.NET MVC 3 CheckBoxList 的使用