Re: finding auto_increment value using DatabaseMetaData
Posted by: Mark Matthews
Date: April 15, 2005 09:10AM

Joakim Ahl�n wrote:
> Hi!
> We just switched from the old mm.mysql-driver to
> connector/J. However, i can't find any way to get
> if a column uses auto increment or not via the
> getMetaData-function.
> With mm.mysql this was stated in the
> REMARKS-column of the metadata resultset, but with
> connector/J i can't find it anywhere.
> This is absolutely needed if we are going to use
> connector/J with our application, and we want to
> since we want to upgrade to mysql 4.1 which
> mm.mysql does not support if i am correct.
> Does anybody know how to accomplish this?
> Also, if there is any other way to find out if a
> column is using the auto_increment attribute from
> within java, please help me with this.


The change came about, as MySQL-4.1 and newer now support column-level remarks, so to be JDBC compliant, so when the driver is connected to MySQL-4.1.0 or newer the driver needs to use the comments, not the 'Extra' field from 'SHOW COLUMNS'.

You can get the auto-increment information from ResultSetMetaData.isAutoIncrement(int columnIndex), which works even from an empty result set (i.e you could create the following query SELECT col1, col2, col3 FROM foo WHERE 1=0).



Mark Matthews
Consulting Member Technical Staff - MySQL Enterprise Tools

Options: ReplyQuote

Written By
Re: finding auto_increment value using DatabaseMetaData
April 15, 2005 09:10AM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.