Пример #1
0
 /**
  * @param sql
  * @return
  * @throws SQLException
  */
 private List<Task> getBySql(String sql) throws SQLException {
   Connection conn = null;
   Statement stmt = null;
   try {
     conn = DBUtil.getConnection();
     stmt = conn.createStatement();
     ResultSet rs = stmt.executeQuery(sql);
     List<Task> tasks = new ArrayList<Task>();
     while (rs.next()) {
       Task task = new Task();
       task.setId(rs.getLong("ID"));
       task.setName(rs.getString("NAME"));
       task.setStatus(rs.getInt("STATUS"));
       task.setcTime(rs.getLong("CTIME"));
       task.setfTime(rs.getLong("FTIME"));
       task.setMessage(rs.getString("MESSAGE"));
       task.setType(rs.getString("TYPE"));
       Set<TranOrder> orders = this.orderDAO.getOrders(conn, task.getId());
       task.setOrders(orders);
       tasks.add(task);
     }
     return tasks;
   } catch (Exception e) {
     LOG.error(e.getMessage(), e);
     throw new RuntimeException(e);
   } finally {
     if (stmt != null) {
       stmt.close();
     }
     if (conn != null) {
       conn.close();
     }
   }
 }
Пример #2
0
 /**
  * @param id
  * @return
  * @throws SQLException
  */
 public Task getById(long id) throws SQLException {
   // ID,NAME,STATUS,CTIME,FTIME,MESSAGE,TYPE
   String sql = "select * from " + TABLE_NAME + " where id=" + id;
   Connection conn = null;
   Statement stmt = null;
   try {
     conn = DBUtil.getConnection();
     stmt = conn.createStatement();
     ResultSet rs = stmt.executeQuery(sql);
     if (rs.next()) {
       Task task = new Task();
       task.setId(rs.getLong("ID"));
       task.setName(rs.getString("NAME"));
       task.setStatus(rs.getInt("STATUS"));
       task.setcTime(rs.getLong("CTIME"));
       task.setfTime(rs.getLong("FTIME"));
       task.setMessage(rs.getString("MESSAGE"));
       task.setType(rs.getString("TYPE"));
       Set<TranOrder> orders = this.orderDAO.getOrders(conn, id);
       task.setOrders(orders);
       return task;
     }
   } catch (Exception e) {
     LOG.error(e.getMessage(), e);
     throw new RuntimeException(e);
   } finally {
     if (conn != null) {
       conn.close();
     }
     if (stmt != null) {
       stmt.close();
     }
   }
   return null;
 }