开发者

jdbc result set metadata: getting physical column names on aliased columns

开发者 https://www.devze.com 2023-04-13 06:48 出处:网络
I\'m using jdbc to execute query statements (in jruby) # made-up example sql = \"select \" + \"c.type as cartype, \" +

I'm using jdbc to execute query statements (in jruby)

# made-up example
sql = "select " +
         "c.type as cartype, " +
         "o.id as ownerid, " +
         "o.type as ownertype " +
       "from cars c " +
         "inner join owners o " +
         "on c.vin = o.vin"
# 'stmt' gotten with jdbc-connection.create_statement() 
result_set = stmt.execute_query(sql)开发者_开发问答
meta_data = result_set.get_meta_data()
col_count = result_set.get_column_count()

I can query the various column aliases (get_column_name) and tables (get_table_name) for each column through the column indexes, but I also need the actual/physical names of the columns, un-aliased.

How do I get the physical/actual name of column, as it is defined in the schema ("ownerid" column alias is column "id", for instance)?


From tests with other database types, it looks as though this is database+driver specific. Using mysql get_column_name returns the actual/physical column name while get_column_label returns the alias. As an aside, both database types (mysql and sqlite) return the physical table name through get_table_name.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号