How to get column labels?

Asked by jung sung hun

I decided to do like this.
It's not elegant.

old_stdout = sys.stdout
redirected_output = sys.stdout = StringIO()
exec('print curs._meta')
sys.stdout = old_stdout
print redirected_output.getvalue()

then parse string output..

'''
org.hsqldb.jdbc.JDBCResultSetMetaData@1ebd60d[
   column_1=[catalogName=PUBLIC, columnClassName=java.lang.Integer, columnDisplaySize=11, columnLabel=CUST_NAME, columnName=CUST_ID, columnType=4, precision=32, scale=0, schemaName=PUBLIC, tableName=CUSTOMER, isAutoIncrement=false, isCaseSensitive=false, isCurrency=false, isDefinitelyWritable=false, isNullable=1, isReadOnly=false, isSearchable=true, isSigned=true, isWritable=false],
   column_2=[catalogName=PUBLIC, columnClassName=java.lang.String, columnDisplaySize=100, columnLabel=NAME, columnName=NAME, columnType=12, precision=100, scale=0, schemaName=PUBLIC, tableName=CUSTOMER, isAutoIncrement=false, isCaseSensitive=true, isCurrency=false, isDefinitelyWritable=false, isNullable=1, isReadOnly=false, isSearchable=true, isSigned=false, isWritable=false]
]
'''

Question information

Language:
Korean Edit question
Status:
Answered
For:
JayDeBeApi Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Bastian (baztian) said :
#1

Please refer to http://legacy.python.org/dev/peps/pep-0249/#description
In your case
cust_id_name, cust_name_name = curs.description[0][0], curs.description[1][0]
should do the trick

Can you help with this problem?

Provide an answer of your own, or ask jung sung hun for more information if necessary.

To post a message you must log in.