Пример #1
0
 @Override
 public List<CcnFile> listAllCcnFiles(long accountId) throws DbException {
   String sql =
       "select accountId, ccnName, time, filePath, type, size from ccnFile "
           + " where accountId =? or type=? order by time desc";
   List<CcnFile> ret = new ArrayList<CcnFile>();
   Connection conn = null;
   try {
     conn = openConnection();
     PreparedStatement stmt = conn.prepareStatement(sql);
     stmt.setLong(1, accountId);
     stmt.setInt(2, CcnFile.TYPE_PUBLIC);
     ResultSet rs = stmt.executeQuery();
     while (rs.next()) {
       long id = rs.getLong(1);
       String ccnName = rs.getString(2);
       java.util.Date time = new java.util.Date(rs.getTimestamp(3).getTime());
       String filePath = rs.getString(4);
       int type = rs.getInt(5);
       long size = rs.getLong(6);
       CcnFile ccnFile = new CcnFile();
       ccnFile.setAccountId(id);
       ccnFile.setCcnname(ccnName);
       ccnFile.setFilePath(filePath);
       ccnFile.setTime(time);
       ccnFile.setType(type);
       ccnFile.setSize(size);
       ret.add(ccnFile);
     }
     return ret;
   } catch (Exception e) {
     throw new DbException("listAllCcnFiles failed,accountId=" + accountId, e);
   } finally {
     if (conn != null) {
       closeConnection(conn);
     }
   }
 }
Пример #2
0
 @Override
 public void saveCcnFile(CcnFile ccnFile) throws DbException {
   String sql =
       "replace ccnFile(accountId,ccnName,time,filePath,type,size) " + "values(?,?,?,?,?,?)";
   Connection conn = null;
   try {
     conn = openConnection();
     PreparedStatement stmt = conn.prepareStatement(sql);
     stmt.setLong(1, ccnFile.getAccountId());
     stmt.setString(2, ccnFile.getCcnname());
     stmt.setTimestamp(3, new Timestamp(ccnFile.getTime().getTime()));
     stmt.setString(4, ccnFile.getFilePath());
     stmt.setInt(5, ccnFile.getType());
     stmt.setLong(6, ccnFile.getSize());
     stmt.executeUpdate();
   } catch (Exception e) {
     throw new DbException("saveCcnFile failed!,ccnFile=" + ccnFile, e);
   } finally {
     closeConnection(conn);
   }
 }