Example usage for java.sql CallableStatement executeQuery

List of usage examples for java.sql CallableStatement executeQuery

Introduction

In this page you can find the example usage for java.sql CallableStatement executeQuery.

Prototype

ResultSet executeQuery() throws SQLException;

Source Link

Document

Executes the SQL query in this PreparedStatement object and returns the ResultSet object generated by the query.

Usage

From source file:com.mobiaware.auction.data.impl.MySqlDataServiceImpl.java

@Override
public List<Fund> getFundsByUser(final int userUid) {
    List<Fund> objs = Lists.newArrayList();

    Connection conn = null;/* ww  w . j av  a  2 s .  c o  m*/
    CallableStatement stmt = null;
    ResultSet rs = null;

    try {
        conn = _dataSource.getConnection();

        stmt = conn.prepareCall("{call SP_GETFUNDSBYUSER (?)}");
        stmt.setInt(1, userUid);

        rs = stmt.executeQuery();

        while (rs.next()) {
            FundBuilder builder = Fund.newBuilder().setUid(rs.getInt("UID")).setUserUid(rs.getInt("USERUID"))
                    .setBidPrice(rs.getDouble("FUNDPRICE")).setBidDate(rs.getDate("FUNDDATE").getTime());

            objs.add(builder.build());
        }
    } catch (SQLException e) {
        LOG.error(Throwables.getStackTraceAsString(e));
    } finally {
        DbUtils.closeQuietly(conn, stmt, rs);
    }

    if (LOG.isDebugEnabled()) {
        LOG.debug("WATCH [method:{} result:{}]", new Object[] { "get", objs.size() });
    }

    return ImmutableList.copyOf(objs);
}

From source file:com.mobiaware.auction.data.impl.MySqlDataServiceImpl.java

@Override
public int getCategoryCount(final int auctionUid) {
    int count = 0;

    Connection conn = null;/*from www .j av  a  2  s  . c o m*/
    CallableStatement stmt = null;
    ResultSet rs = null;

    try {
        conn = _dataSource.getConnection();

        stmt = conn.prepareCall("{call SP_GETCATEGORYCOUNT (?)}");
        stmt.setInt(1, auctionUid);

        rs = stmt.executeQuery();

        if (rs.next()) {
            count = rs.getInt(1);
        }
    } catch (SQLException e) {
        LOG.error(Throwables.getStackTraceAsString(e));
    } finally {
        DbUtils.closeQuietly(conn, stmt, rs);
    }

    if (LOG.isDebugEnabled()) {
        LOG.debug("CATEGORY [method:{} result:{}]", new Object[] { "count", count });
    }

    return count;
}

From source file:com.mobiaware.auction.data.impl.MySqlDataServiceImpl.java

@Override
public List<Watch> getWatchesByItem(final int itemUid) {
    List<Watch> objs = Lists.newArrayList();

    Connection conn = null;/*from  ww w  .j av  a  2  s  .  c o m*/
    CallableStatement stmt = null;
    ResultSet rs = null;

    try {
        conn = _dataSource.getConnection();

        stmt = conn.prepareCall("{call SP_GETWATCHESBYITEM (?)}");
        stmt.setInt(1, itemUid);

        rs = stmt.executeQuery();

        while (rs.next()) {
            WatchBuilder builder = Watch.newBuilder().setUid(rs.getInt("UID")).setUserUid(rs.getInt("USERUID"))
                    .setItemUid(rs.getInt("ITEMUID"));

            objs.add(builder.build());
        }
    } catch (SQLException e) {
        LOG.error(Throwables.getStackTraceAsString(e));
    } finally {
        DbUtils.closeQuietly(conn, stmt, rs);
    }

    if (LOG.isDebugEnabled()) {
        LOG.debug("WATCH [method:{} result:{}]", new Object[] { "get", objs.size() });
    }

    return ImmutableList.copyOf(objs);
}

From source file:com.mobiaware.auction.data.impl.MySqlDataServiceImpl.java

@Override
public List<Watch> getWatchesByUser(final int userUid) {
    List<Watch> objs = Lists.newArrayList();

    Connection conn = null;//w  w  w . j  a va2 s  . c  om
    CallableStatement stmt = null;
    ResultSet rs = null;

    try {
        conn = _dataSource.getConnection();

        stmt = conn.prepareCall("{call SP_GETWATCHESBYUSER (?)}");
        stmt.setInt(1, userUid);

        rs = stmt.executeQuery();

        while (rs.next()) {
            WatchBuilder builder = Watch.newBuilder().setUid(rs.getInt("UID")).setUserUid(rs.getInt("USERUID"))
                    .setItemUid(rs.getInt("ITEMUID"));

            objs.add(builder.build());
        }
    } catch (SQLException e) {
        LOG.error(Throwables.getStackTraceAsString(e));
    } finally {
        DbUtils.closeQuietly(conn, stmt, rs);
    }

    if (LOG.isDebugEnabled()) {
        LOG.debug("WATCH [method:{} result:{}]", new Object[] { "get", objs.size() });
    }

    return ImmutableList.copyOf(objs);
}

From source file:com.mobiaware.auction.data.impl.MySqlDataServiceImpl.java

@Override
public Bid getMaxBidByItem(final int itemUid) {
    Bid obj = null;//  w  w w.j  av a 2 s . com

    Connection conn = null;
    CallableStatement stmt = null;
    ResultSet rs = null;

    try {
        conn = _dataSource.getConnection();

        stmt = conn.prepareCall("{call SP_GETMAXBIDBYITEM (?)}");
        stmt.setInt(1, itemUid);

        rs = stmt.executeQuery();

        if (rs.next()) {
            BidBuilder builder = Bid.newBuilder().setUid(rs.getInt("UID")).setItemUid(rs.getInt("ITEMUID"))
                    .setUserUid(rs.getInt("USERUID")).setBidPrice(rs.getDouble("BIDPRICE"))
                    .setBidDate(rs.getDate("BIDDATE").getTime());

            obj = builder.build();
        }
    } catch (SQLException e) {
        LOG.error(Throwables.getStackTraceAsString(e));
    } finally {
        DbUtils.closeQuietly(conn, stmt, rs);
    }

    if (LOG.isDebugEnabled()) {
        LOG.debug("BID [method:{} result:{}]",
                new Object[] { "get", obj != null ? obj.toString() : "[error]" });
    }

    return obj;
}

From source file:com.mobiaware.auction.data.impl.MySqlDataServiceImpl.java

@Override
public List<Device> getDevicesByUser(final int userUid) {
    List<Device> objs = Lists.newArrayList();

    Connection conn = null;/*from  w w w  .  java2s . c om*/
    CallableStatement stmt = null;
    ResultSet rs = null;

    try {
        conn = _dataSource.getConnection();

        stmt = conn.prepareCall("{call SP_GETDEVICESFORUSER (?)}");
        stmt.setInt(1, userUid);

        rs = stmt.executeQuery();

        while (rs.next()) {
            DeviceBuilder builder = Device.newBuilder().setUid(rs.getInt("UID"))
                    .setUserUid(rs.getInt("USERUID")).setDeviceId(rs.getString("DEVICEID"))
                    .setDeviceType(rs.getString("DEVICETYPE"));

            objs.add(builder.build());
        }
    } catch (SQLException e) {
        LOG.error(Throwables.getStackTraceAsString(e));
    } finally {
        DbUtils.closeQuietly(conn, stmt, rs);
    }

    if (LOG.isDebugEnabled()) {
        LOG.debug("DEVICE [method:{} result:{}]", new Object[] { "get", objs.size() });
    }

    return ImmutableList.copyOf(objs);
}

From source file:com.mobiaware.auction.data.impl.MySqlDataServiceImpl.java

@Override
public List<Item> getItemsUpdatesOnly(final int auctionUid) {
    List<Item> objs = Lists.newArrayList();

    Connection conn = null;//from   www  .  j av a2 s  . c  o  m
    CallableStatement stmt = null;
    ResultSet rs = null;

    try {
        conn = _dataSource.getConnection();

        stmt = conn.prepareCall("{call SP_GETITEMUPDATES (?)}");
        stmt.setInt(1, auctionUid);

        rs = stmt.executeQuery();

        while (rs.next()) {
            ItemBuilder builder = Item.newBuilder().setUid(rs.getInt("UID"))
                    .setAuctionUid(rs.getInt("AUCTIONUID")).setItemNumber(rs.getString("ITEMNUMBER"))
                    .sertCurPrice(rs.getDouble("CURPRICE")).setWinner(rs.getString("WINNER"))
                    .setBidCount(rs.getInt("BIDCOUNT")).setWatchCount(rs.getInt("WATCHCOUNT"));

            objs.add(builder.build());
        }
    } catch (SQLException e) {
        LOG.error(Throwables.getStackTraceAsString(e));
    } finally {
        DbUtils.closeQuietly(conn, stmt, rs);
    }

    if (LOG.isDebugEnabled()) {
        LOG.debug("ITEM [method:{} result:{}]", new Object[] { "get", objs.size() });
    }

    return ImmutableList.copyOf(objs);
}

From source file:com.mobiaware.auction.data.impl.MySqlDataServiceImpl.java

@Override
public Auction getAuction(final int uid) {
    Auction obj = null;//from  w  ww  .j av a2  s  .  c  o  m

    Connection conn = null;
    CallableStatement stmt = null;
    ResultSet rs = null;

    try {
        conn = _dataSource.getConnection();

        stmt = conn.prepareCall("{call SP_GETAUCTION (?)}");
        stmt.setInt(1, uid);

        rs = stmt.executeQuery();

        if (rs.next()) {
            AuctionBuilder builder = Auction.newBuilder().setUid(rs.getInt("UID"))
                    .setName(rs.getString("NAME"));

            Date startdate = rs.getDate("STARTDATE");
            if (startdate != null) {
                builder.setStartDate(startdate.getTime());
            }

            Date enddate = rs.getDate("ENDDATE");
            if (enddate != null) {
                builder.setEndDate(enddate.getTime());
            }

            builder.setLogoUrl(rs.getString("LOGOURL"));
            builder.setColor(rs.getString("COLOR"));

            obj = builder.build();
        }
    } catch (SQLException e) {
        LOG.error(Throwables.getStackTraceAsString(e));
    } finally {
        DbUtils.closeQuietly(conn, stmt, rs);
    }

    if (LOG.isDebugEnabled()) {
        LOG.debug("AUCTION [method:{} result:{}]",
                new Object[] { "get", obj != null ? obj.toString() : "[error]" });
    }

    return obj;
}

From source file:com.mobiaware.auction.data.impl.MySqlDataServiceImpl.java

@Override
public User getUserByBidderNumber(final String biddernumber) {
    User obj = null;/*from w ww .ja  va2  s.  c o m*/

    Connection conn = null;
    CallableStatement stmt = null;
    ResultSet rs = null;

    try {
        conn = _dataSource.getConnection();

        stmt = conn.prepareCall("{call SP_GETUSERBYBIDDERNUMBER (?)}");
        stmt.setString(1, biddernumber);

        rs = stmt.executeQuery();

        if (rs.next()) {
            UserBuilder builder = User.newBuilder().setUid(rs.getInt("UID"))
                    .setAuctionUid(rs.getInt("AUCTIONUID")).setBidderNumber(rs.getString("BIDDERNUMBER"))
                    .setFirstName(rs.getString("FIRSTNAME")).setLastName(rs.getString("LASTNAME"))
                    .setRole(Roles.getId(rs.getInt("ROLE")));

            obj = builder.build();
            obj.setPasswordHash(rs.getString("PASSWORDHASH"));
        }
    } catch (SQLException e) {
        LOG.error(Throwables.getStackTraceAsString(e));
    } finally {
        DbUtils.closeQuietly(conn, stmt, rs);
    }

    if (LOG.isDebugEnabled()) {
        LOG.debug("USER [method:{} result:{}]",
                new Object[] { "get", obj != null ? obj.toString() : "[error]" });
    }

    return obj;
}

From source file:com.mobiaware.auction.data.impl.MySqlDataServiceImpl.java

@Override
public int getItemCount(final int auctionUid, final int categoryuid) {
    int count = 0;

    Connection conn = null;/*  w w  w  . j  av  a 2  s .c om*/
    CallableStatement stmt = null;
    ResultSet rs = null;

    try {
        conn = _dataSource.getConnection();

        stmt = conn.prepareCall("{call SP_GETITEMCOUNT (?,?)}");
        stmt.setInt(1, auctionUid);
        stmt.setInt(2, categoryuid);

        rs = stmt.executeQuery();

        if (rs.next()) {
            count = rs.getInt(1);
        }
    } catch (SQLException e) {
        LOG.error(Throwables.getStackTraceAsString(e));
    } finally {
        DbUtils.closeQuietly(conn, stmt, rs);
    }

    if (LOG.isDebugEnabled()) {
        LOG.debug("ITEM [method:{} result:{}]", new Object[] { "count", count });
    }

    return count;
}