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.
Joakim,
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).
Regards,
-Mark
Mark Matthews
Consulting Member Technical Staff - MySQL Enterprise Tools
Oracle
http://www.mysql.com/products/enterprise/monitor.html