Comments - About MariaDB Connector/J
Content reproduced on this site is the property of its respective owners,
and this content is not reviewed in advance by MariaDB. The views, information and opinions
expressed by this content do not necessarily represent those of MariaDB or any other party.
Not sure what you're refering to when speaking about primary keys. For autoincrement, the things are standard, and you could use getGeneratedKeys() as described here for example http://dev.mysql.com/doc/connector-j/en/connector-j-usagenotes-last-insert-id.html .
Thank you for the link.
The situation in my case is different. Here is a simplified code for my example where normally I get the auto-increment:
ResultSet rscol = null;
String autoInc =null;
int colAutoInc=0;
Statement stmt = cnx.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
ResultSet rs = stmt.executeQuery("Select * from " + db_table);
DatabaseMetaData dbmd =cnx.getMetaData();cnx=Connection
for (i = 1; i <=numberOfColumns; i++) {
rscol = dbmd.getColumns(tableCatalog, tableSchema, db_table, columnName);
while (rscol.next()) {
autoInc = rscol.getString(12);returns "auto-increment" if column is in fact auto-increment
if (!autoInc.equals("")) colAutoInc=i;
}
}
http://docs.oracle.com/javase/7/docs/api/java/sql/DatabaseMetaData.html#getColumns%28java.lang.String,%20java.lang.String,%20java.lang.String,%20java.lang.String%29
It says the column #12 is REMARKS, which does not have much meaning
To retrieve primary key, there is a DatabaseMetaData.getPrimaryKeys() that does exactly that. http://docs.oracle.com/javase/7/docs/api/java/sql/DatabaseMetaData.html#getPrimaryKeys%28java.lang.String,%20java.lang.String,%20java.lang.String%29