环境:
OS:Windows
DB:18.1
1.配置环境变量
TNS_ADMIN=C:\TimesTen\tt181_64\network\admin
2.创建tnsnames.ora文件
在timesten安装目录下
C:\TimesTen\tt181_64\network\admin\samples
拷贝一个tnsnames.ora到C:\TimesTen\tt181_64\network\admin进行修改
3.修改tnsnames.ora
C:\TimesTen\tt181_64\network\admin\tnsnames.ora
添加如下内容:
mytest = (DESCRIPTION = (CONNECT_DATA = (SERVICE_NAME = timesten_dns) (SERVER = timesten_client)))
这里的timesten_dns是在odbc里创建的odbc数据源
4.测试代码
#!/usr/bin/env python #coding=utf-8 import os, json, urllib, datetime, shutil,random,uuid from random import choice import pymysql import traceback import time import cx_Oracle import pyodbc def connect_timesten_db(): connection = cx_Oracle.connect("hxl", "oracle", "mytest") cursor = connection.cursor() cursor.execute("insert into tb_test values (42,42)") connection.commit() connection.close() if __name__ == '__main__': print("开始时间:"+time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))) ##l_flag = insert_data_for_doris() l_flag=connect_timesten_db() print("结束时间:"+time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())))
标签:__,python,timesten,cx,time,import,TimesTen,tt181 From: https://www.cnblogs.com/hxlasky/p/17451916.html