Load data from CSV to Progress database using Python

Here’s a sample Python code to write data from a CSV file to a Progress database using the pyodbc library

import pyodbc
import csv

# Set up the connection to the Progress database
conn = pyodbc.connect('DRIVER={Progress OpenEdge 10.2A Driver};HOST=<your host>;PORT=<port number>;DB=<database name>;UID=<username>;PWD=<password>')

# Set up a cursor to execute SQL queries
cursor = conn.cursor()

# Open the CSV file and read the data
with open('data.csv', 'r') as file:
    csv_data = csv.reader(file)

    # Define the SQL query to insert data into a table
    sql_query = "INSERT INTO my_table (column1, column2, column3) VALUES (?, ?, ?)"

    # Loop through each row of data in the CSV file and insert it into the database
    for row in csv_data:
        cursor.execute(sql_query, (row[0], row[1], row[2]))

# Commit the changes to the database and close the connection
conn.commit()
conn.close()

In this example, we first set up a connection to the Progress database using the pyodbc library. We then define a cursor to execute SQL queries, and open the CSV file using the csv library.

We then define an SQL query to insert data into a table, and loop through each row of data in the CSV file. For each row, we execute the SQL query using the cursor and pass in the values from the row as parameters.

Finally, we commit the changes to the database using the commit() method and close the connection.

Pamai Tech
Turning ideas into Reality

Products

Office Add-in

Enterprise Solutions

Cloud Consulting

UI UX Design

Data Transformation

Services

FAQ's

Privacy Policy

Terms & Condition

Team

Contact Us

Company

About Us

Services

Features

Our Pricing

Latest News

© 2023 Pamai Tech