资源预览内容
第1页 / 共3页
第2页 / 共3页
第3页 / 共3页
亲,该文档总共3页全部预览完了,如果喜欢就下载吧!
资源描述
数据库连接# coding:gbkCreated on 2010-7-15author: Administrator import cx_Oracle dsn=cx_Oracle.makedsn(150.150.1.45,1521,dx) conn=cx_Oracle.connect(test,123,dsn)print 连接oracle成功!try:cur=conn.cursor()sql=select * from portt_type rr=cur.execute(sql) row=cur.fetchall()for x in row:print 记录,x0,x1 cur.close()except Exception,e: print eelse:print 一切正常finally:conn.close() print 连接关闭数据库操作# coding:gbkCreated on 2010-7-15author: Administrator import cx_Oracle#用户名,密码,服务名db=cx_Oracle.connect(user,pass,tns_name)c=db.cursor(); #建表c.execute(create table test(a int,b varchar2(100) )#建序列c.execute(create sequence stest) #插入数据c.execute(insert into test(a,b) values(stest.nextval,Python) )c.execute(insert into test(a,b) values(stest.nextval,Oracle) ) #检索插入的数据sql = select * from testr = c.execute(sql) row = c.fetchone() while row: (a,b)=(row0,row1) print a,b row=c.fetchone()#删除插入的数据sql = delete from test where a=1c.execute(sql) #检索sql = select * from testr = c.execute(sql) row = c.fetchone() while row: (a,b)=(row0,row1) print a,b row=c.fetchone()#清理表和序列c.execute(drop table test) c.execute(drop sequence stest) mit()db.close()
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号