Entry 4798
Oracle connection test
Submitted by Philip Soo Kim
on June 7, 2010 at 10:34 a.m.
Language: Python. Code size: 654 bytes.
#!/usr/bin/env python2.6 import cx_Oracle import pprint def main(): connection = cx_Oracle.Connection("%s/%s@%s" % (user, passwd, sid)) cursor = cx_Oracle.Cursor(connection) sql = "SELECT * FROM test_table" cursor.execute(sql) data = cursor.fetchall() print "#-descriptions:", len(cursor.description) row_names = [] for i in range(0, len(cursor.description)): row_names.append(cursor.description[i][0]) pp = pprint.PrettyPrinter(width=1024) pp.pprint(row_names) pp.pprint(data) cursor.close() connection.close() if __name__ == '__main__': main()
This snippet took 0.01 seconds to highlight.
Back to the Entry List or Home.