ResultSetMetaData怎么获取主键
的有关信息介绍如下:方法一:通过connection来获得 Java代码 :private String getIdName(Connection conn,String tableName){ String idName = ""; DatabaseMetaData metaData = null; try { metaData = conn.getMetaData(); ResultSet rs = metaData.getColumns(conn.getCatalog(), "%", tableName, "%ID"); if(rs.next()){ idName = rs.getString("COLUMN_NAME"); } } catch (Exception e) { logger.error(e); } return idName; } 方法二:通过结果集ResultSet获得 Java代码 :private String getIdName(ResultSet rs){ String idName = ""; ResultSetMetaData metaData = null; try { metaData = rs.getMetaData(); idName = metaData.getColumnName(1); } catch (Exception e) { logger.error("查询表的主键名出错! ",e); } return idName; } 其中rs为select * from tableName;的结果集。