Home > Back-end > JDBC query common beginner can practice logic
JDBC query common beginner can practice logic
Time:12-09
Static int l;
The public & lt; T> List GetAll (String SQL, T classS, Object... Objects) Throws NoSuchFieldException SecurityException, IllegalArgumentException, IllegalAccessException { List ListNews_detail=null; L=objects. Length;//the Object... Objects in the form of an array length return Object [] params=new Object [l];//instantiate the length of the array is L for (int i=0; I & lt; Objects. Length; I++) { Params [I]=objects [I];//instantiate an array of assignment after + + l; } The ResultSet rs=QueryDataBase (SQL, params);//call the method Try { Class<? Extends Object> Newclass=classS. GetClass ();//reflection classS The Object newInstance=null; ListNews_detail=new ArrayList<> (a);//define an array of Class<?> Class.forname=Class. Class.forname (Newclass getName ());//reflection The Field [] declaredFields=class.forname. GetDeclaredFields ();//reflecting classS class attribute to an array of String columnName=null; While (rs), next ()) {//a pointer pointing to the line NewInstance=class.forname. NewInstance ();//call the structure data type and database data types as For (int j=0; J & lt; DeclaredFields. Length; J++) {//declaredFields length attribute number //declaredFields [j] getName () an array name -- through class.forname. GetDeclaredField return property (not attribute string) Field declaredField=class.forname. GetDeclaredField (declaredFields [j]. J getName ()); Class<?> Type=(Class
String SQL="SELECT id, categoryId, summary the FROM news_detail WHERE the summary=? "; BestDao dao=new BestDao (); News_detail detail=new News_detail (); ListFor (the Object Object: all) { System. The out. Println (object); }
CodePudding user response:
If you see this is for new entrants, you named this style should be some specification, Moreover, the couple look not to understand, the old man didn't want to see