* @param tableName 表名
* @return Table对象
*/
@SuppressWarnings("resource")
public static Table getTableMeta(DataSource ds, String tableName) {
final Table table = Table.create(tableName);
Connection conn = null;
ResultSet rs = null;
try {
conn = ds.getConnection();
final DatabaseMetaData metaData = conn.getMetaData();
//获得主键
rs = metaData.getPrimaryKeys(conn.getCatalog(), null, tableName);
while(rs.next()) {
table.addPk("COLUMN_NAME");
}
//获得列
rs = metaData.getColumns(conn.getCatalog(), null, tableName, null);
while(rs.next()) {
table.setColumn(Column.create(tableName, rs));
}
} catch (Exception e) {
throw new UtilException("Get columns error!", e);
}finally {
close(rs, conn);