Ejemplo n.º 1
0
 public List<T> get(WhereUtil wUtil, String orderby) throws Exception {
   Connection conn = null;
   ResultSet rSet = null;
   List<T> t = null;
   try {
     conn = DBManager.getConnection();
     String sql = String.format("select * from %s  %s", getTableName(), wUtil.getWhere());
     if (orderby != null) {
       sql = String.format("%s %s", sql, orderby);
     }
     rSet = execSql(sql, conn, wUtil.getParams());
     if (null == rSet) {
       return null;
     } else {
       @SuppressWarnings("unchecked")
       ResultSetToObject<T> rObject = new ResultSetToObject<T>();
       t = rObject.mapRersultSetToList(rSet);
       return t;
     }
   } catch (Exception e) {
     // TODO: handle exception
   } finally {
     DBManager.freeConnection(conn);
   }
   return t;
 }
Ejemplo n.º 2
0
 public List<T> get(String sql, Object... params) {
   Connection conn = null;
   ResultSet rSet = null;
   List<T> t = null;
   try {
     conn = DBManager.getConnection();
     rSet = execSql(sql, conn, params);
     if (null == rSet) {
       return null;
     } else {
       @SuppressWarnings("unchecked")
       ResultSetToObject<T> rObject = new ResultSetToObject<T>();
       t = rObject.mapRersultSetToList(rSet);
       return t;
     }
   } catch (Exception e) {
     // TODO: handle exception
   } finally {
     DBManager.freeConnection(conn);
   }
   return t;
 }
Ejemplo n.º 3
0
 public T get(int id) throws SQLException {
   Connection connection = null;
   ResultSet rSet = null;
   T t = null;
   try {
     connection = DBManager.getConnection();
     String sql = String.format("Select * from %s where %s=?", getTableName(), getTablePK());
     rSet = execSql(sql, connection, id);
     if (null == rSet) {
       return null;
     } else {
       @SuppressWarnings("unchecked")
       ResultSetToObject<T> rObject = new ResultSetToObject<T>();
       t = rObject.RersultSetToObject(rSet, getTClass());
       return t;
     }
   } catch (Exception e) {
     // TODO: handle exception
     e.printStackTrace();
   } finally {
     DBManager.freeConnection(connection);
   }
   return t;
 }
Ejemplo n.º 4
0
 /** ********************** 本类使用私有方法 ****************************** */
 private List<T> convert(ResultSet rSet) throws SQLException {
   ResultSetToObject<T> rObject = new ResultSetToObject<T>();
   List<T> result = rObject.mapRersultSetToList(rSet);
   return result;
 }