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 int deleteItem(final int uid) {
    int result = -1;

    Connection conn = null;/*w ww .  j  a v  a  2s. co m*/
    CallableStatement stmt = null;
    ResultSet rs = null;

    try {
        conn = _dataSource.getConnection();

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

        rs = stmt.executeQuery();

        if (rs.next()) {
            result = 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[] { "delet", result });
    }

    return result;
}

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

@Override
public int deleteUser(final int uid) {
    int result = -1;

    Connection conn = null;//from w ww  .j  a  va2s . c om
    CallableStatement stmt = null;
    ResultSet rs = null;

    try {
        conn = _dataSource.getConnection();

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

        rs = stmt.executeQuery();

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

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

    return result;
}

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

@Override
public int deleteAuction(final int uid) {
    int result = -1;

    Connection conn = null;//from   w  w  w .  j  ava2s  .c  o m
    CallableStatement stmt = null;
    ResultSet rs = null;

    try {
        conn = _dataSource.getConnection();

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

        rs = stmt.executeQuery();

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

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

    return result;
}

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

@Override
public int deleteCategory(final int uid) {
    int result = -1;

    Connection conn = null;// w w  w  .  jav a 2s .c  o m
    CallableStatement stmt = null;
    ResultSet rs = null;

    try {
        conn = _dataSource.getConnection();

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

        rs = stmt.executeQuery();

        if (rs.next()) {
            result = 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[] { "delete", result });
    }

    return result;
}

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

@Override
public User getUser(final int uid) {
    User obj = null;/*from   www. java  2 s  .c  o  m*/

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

    try {
        conn = _dataSource.getConnection();

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

        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 Category getCategory(final int uid) {
    Category obj = null;// w  ww .  j a v a  2  s .  c o m

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

    try {
        conn = _dataSource.getConnection();

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

        rs = stmt.executeQuery();

        while (rs.next()) {
            CategoryBuilder builder = Category.newBuilder().setUid(rs.getInt("UID"))
                    .setAuctionUid(rs.getInt("AUCTIONUID")).setName(rs.getString("NAME"));

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

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

    return obj;
}

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

@Override
public Item getItem(final int uid) {
    Item obj = null;/*ww  w.  j a  v  a  2  s. c  om*/

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

    try {
        conn = _dataSource.getConnection();

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

        rs = stmt.executeQuery();

        if (rs.next()) {
            ItemBuilder builder = Item.newBuilder().setUid(rs.getInt("UID"))
                    .setAuctionUid(rs.getInt("AUCTIONUID")).setItemNumber(rs.getString("ITEMNUMBER"))
                    .setName(rs.getString("NAME")).setDescription(rs.getString("DESCRIPTION"))
                    .setCategory(rs.getString("CATEGORY")).setSeller(rs.getString("SELLER"))
                    .setValPrice(rs.getDouble("VALPRICE")).setMinPrice(rs.getDouble("MINPRICE"))
                    .setIncPrice(rs.getDouble("INCPRICE")).sertCurPrice(rs.getDouble("CURPRICE"))
                    .setWinner(rs.getString("WINNER")).setBidCount(rs.getInt("BIDCOUNT"))
                    .setWatchCount(rs.getInt("WATCHCOUNT")).setUrl(rs.getString("URL"))
                    .setMultiSale(rs.getBoolean("MULTI"));

            obj = 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", obj != null ? obj.toString() : "[error]" });
    }

    return obj;
}

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

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

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

    try {
        conn = _dataSource.getConnection();

        stmt = conn.prepareCall("{call SP_GETUSERCOUNT (?)}");
        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("USER [method:{} result:{}]", new Object[] { "count", count });
    }

    return count;
}

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

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

    Connection conn = null;/*from   www . jav a  2s . c om*/
    CallableStatement stmt = null;
    ResultSet rs = null;

    try {
        conn = _dataSource.getConnection();

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

        rs = stmt.executeQuery();

        while (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());

            objs.add(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", objs.size() });
    }

    return ImmutableList.copyOf(objs);
}

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

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

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

    try {
        conn = _dataSource.getConnection();

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

        rs = stmt.executeQuery();

        while (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());

            objs.add(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", objs.size() });
    }

    return ImmutableList.copyOf(objs);
}