# Convert **Published by:** [JinJu’s road](https://paragraph.com/@myjinju/) **Published on:** 2022-01-19 **URL:** https://paragraph.com/@myjinju/convert ## Content private static <T> T convert(ResultSet set, Class<T> clazz) { try { Constructor<T> constructor = clazz.getConstructor (clazz.getConstructors()[0].getParameterTypes()); Class<?>[] param = constructor.getParameterTypes(); Object[] objects = new Object[param.length]; for (int i = 0; i < param.length; i++) { objects[i] = set.getObject(i + 1); if (objects[i].getClass() != param[i]) { throw new SQLException("错误类型转换"); } } return constructor.newInstance(objects); } catch (ReflectiveOperationException | SQLException e) { e.printStackTrace(); return null; } } ## Publication Information - [JinJu’s road](https://paragraph.com/@myjinju/): Publication homepage - [All Posts](https://paragraph.com/@myjinju/): More posts from this publication - [RSS Feed](https://api.paragraph.com/blogs/rss/@myjinju): Subscribe to updates - [Twitter](https://twitter.com/pukibopu9): Follow on Twitter