Example usage for java.sql CallableStatement setInt

List of usage examples for java.sql CallableStatement setInt

Introduction

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

Prototype

void setInt(String parameterName, int x) throws SQLException;

Source Link

Document

Sets the designated parameter to the given Java int value.

Usage

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  .co m
    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 getUserCount(final int auctionUid) {
    int count = 0;

    Connection conn = null;/*from www  .j a va 2s . 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 int deleteAuction(final int uid) {
    int result = -1;

    Connection conn = null;//  w  ww .  j  a va  2s .  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  ww.j a v  a2s.co  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;//ww w. ja va 2s  .c om

    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;//from w  w w .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 int getItemCount(final int auctionUid, final int categoryuid) {
    int count = 0;

    Connection conn = null;/*from   w  w  w  . j av a 2s  .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;
}

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

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

    Connection conn = null;//from  w ww . ja  va2s  .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<Bid> getBidsByItem(final int itemUid) {
    List<Bid> objs = Lists.newArrayList();

    Connection conn = null;// w  ww.  ja v a2  s.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;/*from w  ww  .  ja  v  a 2 s  .co  m*/
    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);
}