Skip to content

Instantly share code, notes, and snippets.

@mbiette
Last active August 29, 2015 14:14
Show Gist options
  • Save mbiette/8941cb745fda558bd748 to your computer and use it in GitHub Desktop.
Save mbiette/8941cb745fda558bd748 to your computer and use it in GitHub Desktop.
Connect to an AS/400 (iSeries) using ADODB.
import win32com.client
def main(host, iasp, library, file):
conn = win32com.client.Dispatch(r'ADODB.Connection')
DSN=('DRIVER=iSeries Access ODBC Driver;SYSTEM='+host+';DATABASE='+iasp+';COMPRESSION=1;TRANSLATE=1;')
conn.Open(DSN) # Will prompt for username/password or connect with Kerberos
rs = win32com.client.Dispatch(r'ADODB.Recordset')
rs.Open("SELECT * FROM "+library+"."+file, conn, 1, 3)
# Get records and fields one by one
#while not rs.EOF:
# for field in rs.Fields:
# print(field.Name,field.Value)
# rs.MoveNext()
# Just get everything
data = rs.GetRows()
print(data)
conn.Close()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment