Example usage for java.sql PreparedStatement setLong

List of usage examples for java.sql PreparedStatement setLong

Introduction

In this page you can find the example usage for java.sql PreparedStatement setLong.

Prototype

void setLong(int parameterIndex, long x) throws SQLException;

Source Link

Document

Sets the designated parameter to the given Java long value.

Usage

From source file:com.senior.g40.service.UserService.java

public static Profile getProfileByUserId(long userId) throws SQLException {
    Profile pf = null;/*  w  ww  . j av a 2 s.com*/

    Connection conn = ConnectionBuilder.getConnection();
    String sqlCmd = "SELECT * FROM `profile` WHERE userId = ?;";
    PreparedStatement pstm = conn.prepareStatement(sqlCmd);
    pstm.setLong(1, userId);
    ResultSet rs = pstm.executeQuery();

    if (rs.next()) {
        pf = new Profile();
        setProfile(rs, pf);
        conn.close();
        return pf;
    }
    conn.close();
    return null;
}

From source file:com.keybox.manage.db.UserThemeDB.java

/**
 * get user theme//from www. ja v  a2 s.c o  m
 *
 * @param userId object
 * @return user theme object
 */
public static UserSettings getTheme(Long userId) {

    UserSettings theme = null;
    Connection con = null;
    try {
        con = DBUtils.getConn();

        PreparedStatement stmt = con.prepareStatement("select * from user_theme where user_id=?");
        stmt.setLong(1, userId);
        ResultSet rs = stmt.executeQuery();
        if (rs.next()) {
            theme = new UserSettings();
            theme.setBg(rs.getString("bg"));
            theme.setFg(rs.getString("fg"));
            if (StringUtils.isNotEmpty(rs.getString("d1"))) {
                String[] colors = new String[16];
                colors[0] = rs.getString("d1");
                colors[1] = rs.getString("d2");
                colors[2] = rs.getString("d3");
                colors[3] = rs.getString("d4");
                colors[4] = rs.getString("d5");
                colors[5] = rs.getString("d6");
                colors[6] = rs.getString("d7");
                colors[7] = rs.getString("d8");
                colors[8] = rs.getString("b1");
                colors[9] = rs.getString("b2");
                colors[10] = rs.getString("b3");
                colors[11] = rs.getString("b4");
                colors[12] = rs.getString("b5");
                colors[13] = rs.getString("b6");
                colors[14] = rs.getString("b7");
                colors[15] = rs.getString("b8");
                theme.setColors(colors);
            }
        }
        DBUtils.closeRs(rs);
        DBUtils.closeStmt(stmt);

    } catch (Exception e) {
        log.error(e.toString(), e);
    }
    DBUtils.closeConn(con);

    return theme;

}

From source file:wiki.doc.DocResource.java

public static void insertAll(final List<Doc> docs, DbConnector dbc) {
    BatchPreparedStatementSetter bpss = new BatchPreparedStatementSetter() {
        @Override/* ww  w .j av  a 2  s.  c  o  m*/
        public void setValues(PreparedStatement preparedStatement, int i) throws SQLException {
            preparedStatement.setString(1, docs.get(i).title);
            preparedStatement.setLong(2, docs.get(i).id);
        }

        @Override
        public int getBatchSize() {
            return docs.size();
        }
    };

    dbc.jdbcTemplate.batchUpdate("INSERT INTO pages(title, id) values(?, ?)", bpss);
}

From source file:org.works.integration.storedproc.derby.DerbyStoredProcedures.java

public static void findCoffee(int coffeeId, String[] coffeeDescription) throws SQLException {
    Connection connection = null;
    PreparedStatement statement = null;

    try {//from www  .  ja v  a 2  s  .  c om
        connection = DriverManager.getConnection("jdbc:default:connection");
        String sql = "SELECT * FROM COFFEE_BEVERAGES WHERE ID = ? ";
        statement = connection.prepareStatement(sql);
        statement.setLong(1, coffeeId);

        ResultSet resultset = statement.executeQuery();
        resultset.next();
        coffeeDescription[0] = resultset.getString("COFFEE_DESCRIPTION");

    } finally {
        JdbcUtils.closeStatement(statement);
        JdbcUtils.closeConnection(connection);
    }

}

From source file:com.l2jfree.gameserver.util.IdFactory.java

private static void removeExpired() {
    int removed = 0;

    Connection con = null;//from  ww  w. jav a  2 s . co m
    try {
        con = L2Database.getConnection();

        for (String query : REMOVE_EXPIRED_QUERIES) {
            final PreparedStatement ps = con.prepareStatement(query);
            ps.setLong(1, System.currentTimeMillis());

            removed += ps.executeUpdate();

            ps.close();
        }
    } catch (SQLException e) {
        _log.warn("", e);
    } finally {
        L2Database.close(con);
    }

    _log.info("IdFactory: Removed " + removed + " expired entries from database.");
}

From source file:com.keybox.manage.db.ProfileDB.java

/**
 * deletes profile/*from  w w w  .j  a va 2s.c o  m*/
 *
 * @param profileId profile id
 */
public static void deleteProfile(Long profileId) {

    Connection con = null;
    try {
        con = DBUtils.getConn();
        PreparedStatement stmt = con.prepareStatement("delete from profiles where id=?");
        stmt.setLong(1, profileId);
        stmt.execute();
        DBUtils.closeStmt(stmt);

    } catch (Exception e) {
        log.error(e.toString(), e);
    } finally {
        DBUtils.closeConn(con);
    }
}

From source file:com.l2jfree.sql.L2DatabaseInstaller.java

private static void insertRevision(double revision) {
    System.out.println("Saving revision '" + revision + "'.");

    Connection con = null;//from   w ww. j  av  a 2 s . c o  m
    try {
        con = L2Database.getConnection();

        PreparedStatement ps = con.prepareStatement("INSERT INTO _revision VALUES (?,?)");
        ps.setDouble(1, revision);
        ps.setLong(2, System.currentTimeMillis());
        ps.executeUpdate();
        ps.close();
    } catch (SQLException e) {
        e.printStackTrace();
    } finally {
        L2Database.close(con);
    }

    System.out.println("Done.");
}

From source file:com.keybox.manage.db.ProfileDB.java

/**
 * returns profile based on id/* ww  w.  j  av a2  s . co m*/
 *
 * @param con db connection object
 * @param profileId profile id
 * @return profile
 */
public static Profile getProfile(Connection con, Long profileId) {

    Profile profile = null;
    try {
        PreparedStatement stmt = con.prepareStatement("select * from profiles where id=?");
        stmt.setLong(1, profileId);
        ResultSet rs = stmt.executeQuery();

        while (rs.next()) {
            profile = new Profile();
            profile.setId(rs.getLong("id"));
            profile.setNm(rs.getString("nm"));
            profile.setDesc(rs.getString("desc"));
            profile.setHostSystemList(ProfileSystemsDB.getSystemsByProfile(con, profileId));

        }
        DBUtils.closeRs(rs);
        DBUtils.closeStmt(stmt);

    } catch (Exception e) {
        log.error(e.toString(), e);
    }

    return profile;
}

From source file:ch.newscron.referral.ReferralManager.java

/**
 * Given a customer id and a generated short URL, inserts these two as a new row in the ShortURL table of the database
 * @param customerId an long representing the unique customer id
 * @param shortURL a String representing the short goo.gl generated URL
 *///from   ww  w .  j  a v  a 2s .c o m
public static boolean insertShortURL(long customerId, String shortURL) {
    Connection connection = null;
    PreparedStatement query = null;
    try {
        connection = connect();
        query = connection.prepareStatement("INSERT IGNORE INTO ShortURL (custId, shortUrl) VALUES(?, ?)");
        query.setLong(1, customerId);
        query.setString(2, shortURL);
        int newShortURL = query.executeUpdate();
        return newShortURL == 1;
    } catch (Exception ex) {
        Logger.getLogger(ReferralManager.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        disconnect(connection, query);
    }
    return false;
}

From source file:com.keybox.manage.db.SystemStatusDB.java

/**
 * deletes all records from status table for user
 *
 * @param con DB connection object/* www.  j  a v  a 2s .c om*/
 * @param userId user id
 */
private static void deleteAllSystemStatus(Connection con, Long userId) {

    try {

        PreparedStatement stmt = con.prepareStatement("delete from status where user_id=?");
        stmt.setLong(1, userId);
        stmt.execute();
        DBUtils.closeStmt(stmt);

    } catch (Exception e) {
        log.error(e.toString(), e);
    }

}