Exemplo n.º 1
0
  public static List<NewsPoll> selectAll() throws FtdException {
    List<NewsPoll> newsPolls = new ArrayList<NewsPoll>();

    DBClient dbClient = SysMgr.getInstance().getDbClient();
    String sql = "select * from news_poll";

    CachedRowSet rs = null;
    try {
      rs = dbClient.executeQuery(sql);

      if (rs != null) {
        while (rs.next()) {
          NewsPoll np = new NewsPoll();
          np.setNewsId(rs.getInt("news_id"));
          np.setNewsTitle(rs.getString("news_title"));
          np.setPollImgUrl(rs.getString("poll_img_url"));
          np.setArticleId(rs.getInt("article_id"));
          np.setActive(rs.getInt("is_active"));
          newsPolls.add(np);
        }
      }
    } catch (SQLException e) {
      throw new FtdException(e, "db.sql.error");
    } finally {
      if (rs != null)
        try {
          rs.close();
        } catch (SQLException e) {
          // do nothing
        }
    }

    return newsPolls;
  }
  /**
   * @throws Exception
   * @tests java.sql.rowset.joinRowSet#getWhereClause()
   */
  public void testGetWhereClause_MultipleCachedRowSet() throws Exception {
    String whereClause;

    // Creates another cached rowset.
    CachedRowSet crset2;
    crset2 = newNoInitialInstance();
    crset2.setCommand("SELECT * FROM BOOKS");
    crset2.setUrl(DERBY_URL);
    crset2.execute();

    // Tests when there are on jdbcRowSet and one CachedRowSet.
    jrs.addRowSet(crset2, 1);
    jrs.addRowSet(crset, 1);

    if (System.getProperty("Testing Harmony") == "true") {
      whereClause = jrs.getWhereClause();
      assertNotNull(whereClause);
    } else {
      try {
        whereClause = jrs.getWhereClause();
        fail("Should throw NullPointerException.");
      } catch (NullPointerException e) {
        // Expected.
      }
    }
    crset.setTableName("Table1");
    crset2.setTableName("Table2");
    if (System.getProperty("Testing Harmony") == "true") {
      whereClause = jrs.getWhereClause();
      assertNotNull(whereClause);
    } else {
      try {
        whereClause = jrs.getWhereClause();
        fail("Should throw SQLException.");
      } catch (SQLException e) {
        // Expected.
      }
    }

    crset.setMatchColumn("ID");
    crset2.setMatchColumn("AUTHORID");
    whereClause = jrs.getWhereClause();
    assertNotNull(whereClause);

    jrs = newJoinRowSet();
    jrs.addRowSet(crset2, "AUTHORID");
    jrs.addRowSet(crset, "ID");
    whereClause = jrs.getWhereClause();
    assertNotNull(whereClause);

    crset2.close();
  }
  public static void main(String[] args) {
    boolean successFlag = false;
    CreateConnection.loadProperties();
    try (Connection conn = CreateConnection.getConnection(); ) {

      // Perform Scrollable Query
      queryBookAuthor(conn);
      queryAuthorWork(conn);
      joinRowQuery();
    } catch (java.sql.SQLException ex) {
      System.out.println(ex);
    } finally {

      if (bookAuthors != null) {
        try {
          bookAuthors.close();
        } catch (SQLException ex) {
          ex.printStackTrace();
        }
      }
      if (authorWork != null) {
        try {
          authorWork.close();
        } catch (SQLException ex) {
          ex.printStackTrace();
        }
      }
      if (jrs != null) {

        try {
          jrs.close();
        } catch (SQLException ex) {
          ex.printStackTrace();
        }
      }
    }
  }
  @Test
  public void testGetInfoRowSet() {
    CachedRowSet rws;
    try {
      rws = new CachedRowSetImpl();

      rws.setCommand(ALLEGATO5_FIND_BYPK);
      rws.setInt(1, 6);
      rws.execute(conn);
      rws.next();
      allegato5 = Allegato5Assembler.getInfo(rws);
      rws.close();
      db.closeConnection(conn);

    } catch (SQLException e) {
      fail(e.getMessage());
    } catch (DBAccessException e) {
      fail(e.getMessage());
    }
  }