Python ODBC Example

Do you like this?

Summary:
This short tutorial shows you how to connect to ODBC using Python


Content:

First off, you have to download Python ODBC. There are setup files there which you can use to install the library on your computer.

import pyodbc
connection_string= 'DSN=<Data_Source>;UID=<username>;PWD=<password>'
connection= pyodbc.connect(connection_string)
cursor = connection.cursor()
select_string= "SELECT * FROM TABLE1"
cursor.execute(select_string)
while True:
	row = cursor.fetchone()
	if not row:
		break
	print row
connection.close()

 
comments powered by Disqus