python連線資料庫測試
#!/usr/bin/python
#coding=utf-8
import cx_Oracle
import sys
import urllib
import os
def connectDB(dbname='sms'):
if dbname == 'sms':
connstr='system/oracle@192.168.56.21:1521/sms'
db=cx_Oracle.connect(connstr)
return db
def sqlSelect(sql,db):
#include:select
cr=db.cursor()
cr.execute(sql)
rs=cr.fetchall()
cr.close
return rs
def sqlDML(sql,db):
#include:inesrt,update,deleter
cr=db.cursor()
cr.execute(sql)
cr.close()
db.commit
def sqlDDL(sql,db):
#include:create
cr=db.cursor()
cr.execute(sql)
cr.close
if __name__=='__main__':
print "This is a test python program,write by lsq!\n"
#connect to database
db=connectDB()
#create table:
sql="create table test as select rownum id,lpad(rownum,10,'x') comm from dual connect by level<=100"
sqlDDL(sql,db)
#insert data to table test
sql="insert into test select rownum,lpad(rownum,10,'x') from dual connect by level<=100"
sqlDML(sql,db)
#select th result:
print "this is the first time select the data from test"
sql='select * from test'
rs=sqlSelect(sql,db)
for x in rs:
print x
oracle@bjmbsdb01[/home/oracle]python testdb.py
This is a test python program,write by lsq!
this is the first time select the data from test
(1, 'xxxxxxxxx1')
(2, 'xxxxxxxxx2')
(3, 'xxxxxxxxx3')
(4, 'xxxxxxxxx4')
(5, 'xxxxxxxxx5')
(6, 'xxxxxxxxx6')
(7, 'xxxxxxxxx7')
(8, 'xxxxxxxxx8')
(9, 'xxxxxxxxx9')
(10, 'xxxxxxxx10')
(11, 'xxxxxxxx11')
(12, 'xxxxxxxx12')
(13, 'xxxxxxxx13')
(14, 'xxxxxxxx14')
(15, 'xxxxxxxx15')
(16, 'xxxxxxxx16')
(17, 'xxxxxxxx17')
(18, 'xxxxxxxx18')
(19, 'xxxxxxxx19')
(20, 'xxxxxxxx20')
(21, 'xxxxxxxx21')
(22, 'xxxxxxxx22')
(23, 'xxxxxxxx23')
(24, 'xxxxxxxx24')
(25, 'xxxxxxxx25')
(26, 'xxxxxxxx26')
(27, 'xxxxxxxx27')
(28, 'xxxxxxxx28')
(29, 'xxxxxxxx29')
(30, 'xxxxxxxx30')
(31, 'xxxxxxxx31')
(32, 'xxxxxxxx32')
(33, 'xxxxxxxx33')
(34, 'xxxxxxxx34')
(35, 'xxxxxxxx35')
(36, 'xxxxxxxx36')
(37, 'xxxxxxxx37')
(38, 'xxxxxxxx38')
(39, 'xxxxxxxx39')
(40, 'xxxxxxxx40')
(41, 'xxxxxxxx41')
(42, 'xxxxxxxx42')
(43, 'xxxxxxxx43')
(44, 'xxxxxxxx44')
(45, 'xxxxxxxx45')
(46, 'xxxxxxxx46')
(47, 'xxxxxxxx47')
(48, 'xxxxxxxx48')
(49, 'xxxxxxxx49')
(50, 'xxxxxxxx50')
(51, 'xxxxxxxx51')
(52, 'xxxxxxxx52')
(53, 'xxxxxxxx53')
(54, 'xxxxxxxx54')
(55, 'xxxxxxxx55')
(56, 'xxxxxxxx56')
(57, 'xxxxxxxx57')
(58, 'xxxxxxxx58')
(59, 'xxxxxxxx59')
(60, 'xxxxxxxx60')
(61, 'xxxxxxxx61')
(62, 'xxxxxxxx62')
(63, 'xxxxxxxx63')
(64, 'xxxxxxxx64')
(65, 'xxxxxxxx65')
(66, 'xxxxxxxx66')
(67, 'xxxxxxxx67')
(68, 'xxxxxxxx68')
(69, 'xxxxxxxx69')
(70, 'xxxxxxxx70')
(71, 'xxxxxxxx71')
(72, 'xxxxxxxx72')
(73, 'xxxxxxxx73')
(74, 'xxxxxxxx74')
(75, 'xxxxxxxx75')
(76, 'xxxxxxxx76')
(77, 'xxxxxxxx77')
(78, 'xxxxxxxx78')
(79, 'xxxxxxxx79')
(80, 'xxxxxxxx80')
(81, 'xxxxxxxx81')
(82, 'xxxxxxxx82')
(83, 'xxxxxxxx83')
(84, 'xxxxxxxx84')
(85, 'xxxxxxxx85')
(86, 'xxxxxxxx86')
(87, 'xxxxxxxx87')
(88, 'xxxxxxxx88')
(89, 'xxxxxxxx89')
(90, 'xxxxxxxx90')
(91, 'xxxxxxxx91')
(92, 'xxxxxxxx92')
(93, 'xxxxxxxx93')
(94, 'xxxxxxxx94')
(95, 'xxxxxxxx95')
(96, 'xxxxxxxx96')
(97, 'xxxxxxxx97')
(98, 'xxxxxxxx98')
(99, 'xxxxxxxx99')
(100, 'xxxxxxx100')
(1, 'xxxxxxxxx1')
(2, 'xxxxxxxxx2')
(3, 'xxxxxxxxx3')
(4, 'xxxxxxxxx4')
(5, 'xxxxxxxxx5')
(6, 'xxxxxxxxx6')
(7, 'xxxxxxxxx7')
(8, 'xxxxxxxxx8')
(9, 'xxxxxxxxx9')
(10, 'xxxxxxxx10')
(11, 'xxxxxxxx11')
(12, 'xxxxxxxx12')
(13, 'xxxxxxxx13')
(14, 'xxxxxxxx14')
(15, 'xxxxxxxx15')
(16, 'xxxxxxxx16')
(17, 'xxxxxxxx17')
(18, 'xxxxxxxx18')
(19, 'xxxxxxxx19')
(20, 'xxxxxxxx20')
(21, 'xxxxxxxx21')
(22, 'xxxxxxxx22')
(23, 'xxxxxxxx23')
(24, 'xxxxxxxx24')
(25, 'xxxxxxxx25')
(26, 'xxxxxxxx26')
(27, 'xxxxxxxx27')
(28, 'xxxxxxxx28')
(29, 'xxxxxxxx29')
(30, 'xxxxxxxx30')
(31, 'xxxxxxxx31')
(32, 'xxxxxxxx32')
(33, 'xxxxxxxx33')
(34, 'xxxxxxxx34')
(35, 'xxxxxxxx35')
(36, 'xxxxxxxx36')
(37, 'xxxxxxxx37')
(38, 'xxxxxxxx38')
(39, 'xxxxxxxx39')
(40, 'xxxxxxxx40')
(41, 'xxxxxxxx41')
(42, 'xxxxxxxx42')
(43, 'xxxxxxxx43')
(44, 'xxxxxxxx44')
(45, 'xxxxxxxx45')
(46, 'xxxxxxxx46')
(47, 'xxxxxxxx47')
(48, 'xxxxxxxx48')
(49, 'xxxxxxxx49')
(50, 'xxxxxxxx50')
(51, 'xxxxxxxx51')
(52, 'xxxxxxxx52')
(53, 'xxxxxxxx53')
(54, 'xxxxxxxx54')
(55, 'xxxxxxxx55')
(56, 'xxxxxxxx56')
(57, 'xxxxxxxx57')
(58, 'xxxxxxxx58')
(59, 'xxxxxxxx59')
(60, 'xxxxxxxx60')
(61, 'xxxxxxxx61')
(62, 'xxxxxxxx62')
(63, 'xxxxxxxx63')
(64, 'xxxxxxxx64')
(65, 'xxxxxxxx65')
(66, 'xxxxxxxx66')
(67, 'xxxxxxxx67')
(68, 'xxxxxxxx68')
(69, 'xxxxxxxx69')
(70, 'xxxxxxxx70')
(71, 'xxxxxxxx71')
(72, 'xxxxxxxx72')
(73, 'xxxxxxxx73')
(74, 'xxxxxxxx74')
(75, 'xxxxxxxx75')
(76, 'xxxxxxxx76')
(77, 'xxxxxxxx77')
(78, 'xxxxxxxx78')
(79, 'xxxxxxxx79')
(80, 'xxxxxxxx80')
(81, 'xxxxxxxx81')
(82, 'xxxxxxxx82')
(83, 'xxxxxxxx83')
(84, 'xxxxxxxx84')
(85, 'xxxxxxxx85')
(86, 'xxxxxxxx86')
(87, 'xxxxxxxx87')
(88, 'xxxxxxxx88')
(89, 'xxxxxxxx89')
(90, 'xxxxxxxx90')
(91, 'xxxxxxxx91')
(92, 'xxxxxxxx92')
(93, 'xxxxxxxx93')
(94, 'xxxxxxxx94')
(95, 'xxxxxxxx95')
(96, 'xxxxxxxx96')
(97, 'xxxxxxxx97')
(98, 'xxxxxxxx98')
(99, 'xxxxxxxx99')
(100, 'xxxxxxx100')
#coding=utf-8
import cx_Oracle
import sys
import urllib
import os
def connectDB(dbname='sms'):
if dbname == 'sms':
connstr='system/oracle@192.168.56.21:1521/sms'
db=cx_Oracle.connect(connstr)
return db
def sqlSelect(sql,db):
#include:select
cr=db.cursor()
cr.execute(sql)
rs=cr.fetchall()
cr.close
return rs
def sqlDML(sql,db):
#include:inesrt,update,deleter
cr=db.cursor()
cr.execute(sql)
cr.close()
db.commit
def sqlDDL(sql,db):
#include:create
cr=db.cursor()
cr.execute(sql)
cr.close
if __name__=='__main__':
print "This is a test python program,write by lsq!\n"
#connect to database
db=connectDB()
#create table:
sql="create table test as select rownum id,lpad(rownum,10,'x') comm from dual connect by level<=100"
sqlDDL(sql,db)
#insert data to table test
sql="insert into test select rownum,lpad(rownum,10,'x') from dual connect by level<=100"
sqlDML(sql,db)
#select th result:
print "this is the first time select the data from test"
sql='select * from test'
rs=sqlSelect(sql,db)
for x in rs:
print x
oracle@bjmbsdb01[/home/oracle]python testdb.py
This is a test python program,write by lsq!
this is the first time select the data from test
(1, 'xxxxxxxxx1')
(2, 'xxxxxxxxx2')
(3, 'xxxxxxxxx3')
(4, 'xxxxxxxxx4')
(5, 'xxxxxxxxx5')
(6, 'xxxxxxxxx6')
(7, 'xxxxxxxxx7')
(8, 'xxxxxxxxx8')
(9, 'xxxxxxxxx9')
(10, 'xxxxxxxx10')
(11, 'xxxxxxxx11')
(12, 'xxxxxxxx12')
(13, 'xxxxxxxx13')
(14, 'xxxxxxxx14')
(15, 'xxxxxxxx15')
(16, 'xxxxxxxx16')
(17, 'xxxxxxxx17')
(18, 'xxxxxxxx18')
(19, 'xxxxxxxx19')
(20, 'xxxxxxxx20')
(21, 'xxxxxxxx21')
(22, 'xxxxxxxx22')
(23, 'xxxxxxxx23')
(24, 'xxxxxxxx24')
(25, 'xxxxxxxx25')
(26, 'xxxxxxxx26')
(27, 'xxxxxxxx27')
(28, 'xxxxxxxx28')
(29, 'xxxxxxxx29')
(30, 'xxxxxxxx30')
(31, 'xxxxxxxx31')
(32, 'xxxxxxxx32')
(33, 'xxxxxxxx33')
(34, 'xxxxxxxx34')
(35, 'xxxxxxxx35')
(36, 'xxxxxxxx36')
(37, 'xxxxxxxx37')
(38, 'xxxxxxxx38')
(39, 'xxxxxxxx39')
(40, 'xxxxxxxx40')
(41, 'xxxxxxxx41')
(42, 'xxxxxxxx42')
(43, 'xxxxxxxx43')
(44, 'xxxxxxxx44')
(45, 'xxxxxxxx45')
(46, 'xxxxxxxx46')
(47, 'xxxxxxxx47')
(48, 'xxxxxxxx48')
(49, 'xxxxxxxx49')
(50, 'xxxxxxxx50')
(51, 'xxxxxxxx51')
(52, 'xxxxxxxx52')
(53, 'xxxxxxxx53')
(54, 'xxxxxxxx54')
(55, 'xxxxxxxx55')
(56, 'xxxxxxxx56')
(57, 'xxxxxxxx57')
(58, 'xxxxxxxx58')
(59, 'xxxxxxxx59')
(60, 'xxxxxxxx60')
(61, 'xxxxxxxx61')
(62, 'xxxxxxxx62')
(63, 'xxxxxxxx63')
(64, 'xxxxxxxx64')
(65, 'xxxxxxxx65')
(66, 'xxxxxxxx66')
(67, 'xxxxxxxx67')
(68, 'xxxxxxxx68')
(69, 'xxxxxxxx69')
(70, 'xxxxxxxx70')
(71, 'xxxxxxxx71')
(72, 'xxxxxxxx72')
(73, 'xxxxxxxx73')
(74, 'xxxxxxxx74')
(75, 'xxxxxxxx75')
(76, 'xxxxxxxx76')
(77, 'xxxxxxxx77')
(78, 'xxxxxxxx78')
(79, 'xxxxxxxx79')
(80, 'xxxxxxxx80')
(81, 'xxxxxxxx81')
(82, 'xxxxxxxx82')
(83, 'xxxxxxxx83')
(84, 'xxxxxxxx84')
(85, 'xxxxxxxx85')
(86, 'xxxxxxxx86')
(87, 'xxxxxxxx87')
(88, 'xxxxxxxx88')
(89, 'xxxxxxxx89')
(90, 'xxxxxxxx90')
(91, 'xxxxxxxx91')
(92, 'xxxxxxxx92')
(93, 'xxxxxxxx93')
(94, 'xxxxxxxx94')
(95, 'xxxxxxxx95')
(96, 'xxxxxxxx96')
(97, 'xxxxxxxx97')
(98, 'xxxxxxxx98')
(99, 'xxxxxxxx99')
(100, 'xxxxxxx100')
(1, 'xxxxxxxxx1')
(2, 'xxxxxxxxx2')
(3, 'xxxxxxxxx3')
(4, 'xxxxxxxxx4')
(5, 'xxxxxxxxx5')
(6, 'xxxxxxxxx6')
(7, 'xxxxxxxxx7')
(8, 'xxxxxxxxx8')
(9, 'xxxxxxxxx9')
(10, 'xxxxxxxx10')
(11, 'xxxxxxxx11')
(12, 'xxxxxxxx12')
(13, 'xxxxxxxx13')
(14, 'xxxxxxxx14')
(15, 'xxxxxxxx15')
(16, 'xxxxxxxx16')
(17, 'xxxxxxxx17')
(18, 'xxxxxxxx18')
(19, 'xxxxxxxx19')
(20, 'xxxxxxxx20')
(21, 'xxxxxxxx21')
(22, 'xxxxxxxx22')
(23, 'xxxxxxxx23')
(24, 'xxxxxxxx24')
(25, 'xxxxxxxx25')
(26, 'xxxxxxxx26')
(27, 'xxxxxxxx27')
(28, 'xxxxxxxx28')
(29, 'xxxxxxxx29')
(30, 'xxxxxxxx30')
(31, 'xxxxxxxx31')
(32, 'xxxxxxxx32')
(33, 'xxxxxxxx33')
(34, 'xxxxxxxx34')
(35, 'xxxxxxxx35')
(36, 'xxxxxxxx36')
(37, 'xxxxxxxx37')
(38, 'xxxxxxxx38')
(39, 'xxxxxxxx39')
(40, 'xxxxxxxx40')
(41, 'xxxxxxxx41')
(42, 'xxxxxxxx42')
(43, 'xxxxxxxx43')
(44, 'xxxxxxxx44')
(45, 'xxxxxxxx45')
(46, 'xxxxxxxx46')
(47, 'xxxxxxxx47')
(48, 'xxxxxxxx48')
(49, 'xxxxxxxx49')
(50, 'xxxxxxxx50')
(51, 'xxxxxxxx51')
(52, 'xxxxxxxx52')
(53, 'xxxxxxxx53')
(54, 'xxxxxxxx54')
(55, 'xxxxxxxx55')
(56, 'xxxxxxxx56')
(57, 'xxxxxxxx57')
(58, 'xxxxxxxx58')
(59, 'xxxxxxxx59')
(60, 'xxxxxxxx60')
(61, 'xxxxxxxx61')
(62, 'xxxxxxxx62')
(63, 'xxxxxxxx63')
(64, 'xxxxxxxx64')
(65, 'xxxxxxxx65')
(66, 'xxxxxxxx66')
(67, 'xxxxxxxx67')
(68, 'xxxxxxxx68')
(69, 'xxxxxxxx69')
(70, 'xxxxxxxx70')
(71, 'xxxxxxxx71')
(72, 'xxxxxxxx72')
(73, 'xxxxxxxx73')
(74, 'xxxxxxxx74')
(75, 'xxxxxxxx75')
(76, 'xxxxxxxx76')
(77, 'xxxxxxxx77')
(78, 'xxxxxxxx78')
(79, 'xxxxxxxx79')
(80, 'xxxxxxxx80')
(81, 'xxxxxxxx81')
(82, 'xxxxxxxx82')
(83, 'xxxxxxxx83')
(84, 'xxxxxxxx84')
(85, 'xxxxxxxx85')
(86, 'xxxxxxxx86')
(87, 'xxxxxxxx87')
(88, 'xxxxxxxx88')
(89, 'xxxxxxxx89')
(90, 'xxxxxxxx90')
(91, 'xxxxxxxx91')
(92, 'xxxxxxxx92')
(93, 'xxxxxxxx93')
(94, 'xxxxxxxx94')
(95, 'xxxxxxxx95')
(96, 'xxxxxxxx96')
(97, 'xxxxxxxx97')
(98, 'xxxxxxxx98')
(99, 'xxxxxxxx99')
(100, 'xxxxxxx100')
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10972173/viewspace-1434283/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Python連線SQLite資料庫PythonSQLite資料庫
- python資料庫連線池Python資料庫
- 使用Python連線資料庫Python資料庫
- Python連線MySQL資料庫PythonMySql資料庫
- Python 連線 Oracle資料庫PythonOracle資料庫
- python 連線 mongo 資料庫連線超時PythonGo資料庫
- python資料插入連線MySQL資料庫PythonMySql資料庫
- 資料庫與python的連線資料庫Python
- python怎麼連線資料庫Python資料庫
- Python資料庫連線池DButilsPython資料庫
- PostgreSQL:資料庫連結測試SQL資料庫
- TCP 百萬併發 資料連線測試 python+locustTCPPython
- [JM_08]JMeter連線Mysql資料庫測試實踐JMeterMySql資料庫
- 【JDBC】java連線池模擬測試連線Oracle資料庫指令碼參考JDBCJavaOracle資料庫指令碼
- python+selenium 連線MySQL資料庫PythonMySql資料庫
- python操作MySQL資料庫連線(pymysql)PythonMySql資料庫
- python連線mysql資料庫步驟PythonMySql資料庫
- 如何掌握python連線redis資料庫?PythonRedis資料庫
- 深圳軟體測試學習:【資料庫】-【oracle】-連線查詢資料庫Oracle
- 用Navicat連線資料庫-資料庫連線(MySQL演示)資料庫MySql
- Python 連線mysql資料庫進行操作PythonMySql資料庫
- 連線資料庫資料庫
- python資料庫連線池的正確用法Python資料庫
- 資料庫連線池-Druid資料庫連線池原始碼解析資料庫UI原始碼
- mysqli連線資料庫MySql資料庫
- Mongodb資料庫連線MongoDB資料庫
- Android 連線資料庫Android資料庫
- java連線資料庫Java資料庫
- 連線資料庫-mysql資料庫MySql
- jmeter連線資料庫JMeter資料庫
- Mybatis連線資料庫MyBatis資料庫
- JSP連線資料庫JS資料庫
- JDBC連線資料庫JDBC資料庫
- Flask連線資料庫Flask資料庫
- 《四 資料庫連線池原始碼》手寫資料庫連線池資料庫原始碼
- Python+資料庫測試常用關鍵字Python資料庫
- 資料庫的連線數資料庫
- C#連線資料庫C#資料庫
- 如何連線MySQL資料庫MySql資料庫