public void openCon() throws SQLException, ClassNotFoundException {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/li", "root", "root");
}
public List query(String sql,Classc) throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException, SecurityException, NoSuchMethodException, IllegalArgumentException, InvocationTargetException{
openCon();
sta =con.createStatement();
rs=sta.executeQuery(sql);
List list =new ArrayList();
while(rs.next()){
T o =c.newInstance();
Field[] f =c.getDeclaredFields();
for (int i = 0; i < f.length; i++) {
String methodName ="set"+f[i].getName().substring(0,1).toUpperCase()+f[i].getName().substring(1);
Method m =c.getMethod(methodName, String.class);
m.invoke(o, rs.getString(f[i].getName()));
}
list.add(o);
}
close();
return list;
}