Example #1
0
    public MetadataBlob[] select(String selectString) {
      PreparedStatement stmt = null;
      try {
        stmt =
            conn.prepareStatement(
                "select writingKey, mapkey, blobdata from metadatablobs " + selectString + ";");
        ResultSet rs = stmt.executeQuery();
        List<MetadataBlob> list = new ArrayList<MetadataBlob>();
        while (rs.next()) {
          MetadataBlob f =
              new MetadataBlob(
                  rs.getString("writingkey"), rs.getString("mapkey"), rs.getString("blobdata"));
          list.add(f);
        }

        return list.toArray(new MetadataBlob[0]);
      } catch (SQLException sqe) {
        System.err.println("Error selecting: " + selectString);
        sqe.printStackTrace();
        return null;
      } finally {
        if (stmt != null)
          try {
            stmt.close();
          } catch (SQLException sqe2) {
            sqe2.printStackTrace();
          }
      }
    }
Example #2
0
  @Override
  public byte[] getAllUsernamesGzip() throws IOException {
    try (PreparedStatement stmt = conn.prepareStatement("select name from users")) {
      ResultSet rs = stmt.executeQuery();
      List<String> list = new ArrayList<>();
      while (rs.next()) {
        String username = rs.getString("name");
        list.add(username);
      }

      ByteArrayOutputStream bout = new ByteArrayOutputStream();
      try (DataOutputStream dout = new DataOutputStream(new GZIPOutputStream(bout))) {

        for (String uname : list) Serialize.serialize(uname, dout);
      }
      return bout.toByteArray();
    } catch (SQLException sqe) {
      throw new IOException(sqe);
    }
  }
Example #3
0
 public RowData[] select() {
   PreparedStatement stmt = null;
   try {
     stmt = conn.prepareStatement(selectStatement());
     ResultSet rs = stmt.executeQuery();
     List<RowData> list = new ArrayList<>();
     while (rs.next()) {
       String username = rs.getString("name");
       String b64string = rs.getString(b64DataName());
       list.add(new UserData(username, b64string));
     }
     return list.toArray(new RowData[0]);
   } catch (SQLException sqe) {
     sqe.printStackTrace();
     return null;
   } finally {
     if (stmt != null)
       try {
         stmt.close();
       } catch (SQLException sqe2) {
         sqe2.printStackTrace();
       }
   }
 }