To check if a column is auto incremented i can do the following
Connection con = ...
DatabaseMetaData meta = con.getMetaData();
ResultSet metaCols = meta.getColumns(catalog, schema, table, "%");
while ( metaCols.next() )
String value = rs.getString("IS_AUTOINCREMENT")
...
works fine except with Sybase databases. I've tried it with the jTDS and JConnect drivers, but with both drivers I get the this exception:
java.sql.SQLException: Invalid column name IS_AUTOINCREMENT.
Is there another the get find out, whether a column in Sybase is auto incremented or not? I thought "IS_AUTOINCREMENT" is a feature with JDBC4 and jTDS is a JDBC4 compatible driver.
sp_help delivers all the information I need. This SP returns several ResultSets. The third ResultSet contains the information I need.
Statement stmt = con.createStatement();
stmt.executeQuery("sp_help " + table);
stmt.getMoreResults();
stmt.getMoreResults();
ResultSet rs = stmt.getResultSet();
//...
while( rs.next() )
boolean identity = rs.getBoolean("Identity");