python 插入日期資料到Oracle

zhaoyangjian724發表於2017-11-10
 [root@yyjk DATABASE]# cat DBI.py
# -*- coding: utf-8 -*- 
import cx_Oracle 
import time
import datetime
class DBI (object):
 def LoadDB(self,a,b): 
   print self
   conn = cx_Oracle.connect('tlcbuser/tlcbuser@1.1.1.1/tlyy')  
   cursor = conn.cursor()
   #coding:UTF-8
   #獲取當前時間
   time_now = int(time.time())
   #轉換成localtime
   #time_local = time.localtime(time_now)
   #print time_local
   #dt = time.strftime("%Y-%m-%d %H:%M:%S",time_local)
   dt=datetime.datetime.now()
   print dt
   param={'stime':dt,'message':a,'phone':b}
   print param;
   cursor.execute('insert into tlcb_python_sms values(:stime,:message,:phone)',param)
   conn.commit()
   cursor.close
   
   
   python 插入時間到oracle
   
   
SQL> desc tlcb_python_sms
 Name                       Null?    Type
 ----------------------------------------- -------- ----------------------------
 STIME                            DATE
 MESSAGE                        VARCHAR2(1000)
 PHONE                            VARCHAR2(20)
 
 [root@yyjk flask]# python test.py 
lib.Mojo.Client
<lib.Mojo.Client.New object at 0x7f080e371050>
2017-11-10 11:37:40.173295
{'phone': '222', 'message': '111', 'stime': datetime.datetime(2017, 11, 10, 11, 37, 40, 173295)}

相關文章