國產資料庫oceanBbase,達夢,金倉與mysql資料庫的效能對比 九、python讀金倉資料庫

万笑佛發表於2024-11-20
#coding=utf-8
import psycopg2
import time
#測試單表插入效能

try:
    start_time = time.time()  # 記錄開始時間

    connection1 = conn = psycopg2.connect(host='192.168.0.99', port=54321, user='user', password='pass',  dbname='kingdb')

    # 運算元據庫
    cursor1 = connection1.cursor()  # 建立一個遊標
 
    # 查詢手機資訊
    sql = " select *  from DB_TEST_T"

    # 執行SQL查詢(假設你已經建立了資料庫連線和遊標)
    cursor1.execute(sql)
    # 獲取查詢結果
    rows = cursor1.fetchall()
    i = 0
    for row in rows:
        ID = row[0]


    end_time = time.time()  # 記錄結束時間
    execution_time = end_time - start_time  # 計算執行時間
    print(f"Function execution took {execution_time} seconds")

except psycopg2.Error as e:
    print(f'錯誤:,{e}')

相關文章