我试图从SQL查询方法返回泛型类型,但我坚持将数据库的值分配给泛型类型:
public static <T extends Comparable<T>> T selectQuery(Connection conn, String sql, T[] parameters) {
T value = null;
try {
PreparedStatement ps = conn.prepareStatement(sql);
List<T> list = Arrays.asList(parameters);
for (T param : list) {
if (param instanceof String) {
ps.setString(list.indexOf(param), (String) param);
} else if (param instanceof Integer) {
ps.setInt(list.indexOf(param), (Integer) param);
} else if (param instanceof Double) {
ps.setDouble(list.indexOf(param), (Double) param);
}
}
ResultSet rs = ps.executeQuery();
while (rs.next()) {
//AM STUCK RIGHT HERE************
}
Conn.closeConn(conn);
} catch (Exception asd) {
System.out.println(asd.getMessage());
}
return value;
}
接下来我可以尝试什么?
1条答案
按热度按时间sg3maiej1#
有关Types in sql的更多参考