/** * * @param c * For example Person.class * @param primarykeys * Primarykeys primary key, parameter order and table consistency if ID, The name of the primary key class is GetEntity (person.class,1, "name") * @return */public Static object GetEntity (Class C, object ... prima Rykeys) {PreparedStatement PS = null; ResultSet rs = null;databasemetadata DMD = Null;object obj = null;//the object to return string tableName = C.getsimplename (). Tolowercas E ();//The name of the person table list primarykeynamelist = new ArrayList (); field[] fields = C.getfields ();//Get all the properties StringBuilder sql = new StringBuilder ("SELECT * from" + tablename+ "where"); tr y {obj = c.newinstance ();d MD = getconnection (). GetMetaData (); rs = Dmd.getprimarykeys (null, NULL, tableName); while ( Rs.next ()) {Sql.append (Rs.getobject (4) + "=?"); Sql.append ("and");p Rimarykeynamelist.add (Rs.getobject (4));//The primary key field obtained from the table is stored in the list, and the primary key is located in the table in the first few columns =rs.getstring (5)} Sql.delete (Sql.length ()-4, Sql.length ());p s = (PreparedStatement) getconnection (). Preparestatement (Sql.toString ()) ; for (int l = 0; l < PRImarykeynamelist.size (); l++) {Ps.setobject (L + 1, primarykeys[l]);} rs = Ps.executequery (); System.out.println (Ps.tostring (). Split (":") [1]); if (Rs.next ()) {for (int k = 0; K < Fields.length; k++) {fields[k].set (obj, rs.getobject (k + 1));}} Rs.close ();p s.close (); rs=null;ps=null;} catch (Exception e) {e.printstacktrace ();} finally {}return obj;}