Example usage for java.sql PreparedStatement setBoolean

List of usage examples for java.sql PreparedStatement setBoolean

Introduction

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

Prototype

void setBoolean(int parameterIndex, boolean x) throws SQLException;

Source Link

Document

Sets the designated parameter to the given Java boolean value.

Usage

From source file:com.wso2telco.gsma.authenticators.DBUtils.java

/**
 * Get prompt data/* www . j a v  a  2 s  .  com*/
 *
 * @param scope
 * @param prompt
 * @param isLoginHintExists
 * @return PromptData
 */
public static PromptData getPromptData(String scope, String prompt, Boolean isLoginHintExists) {
    PromptData promptData = new PromptData();
    Connection connection = null;
    PreparedStatement ps = null;
    ResultSet rs = null;

    String sql = "SELECT * FROM prompt_configuration WHERE scope = ? AND prompt_value = ? AND is_login_hint_exists = ?";

    try {
        connection = getConnectDBConnection();
        ps = connection.prepareStatement(sql);
        ps.setString(1, scope);
        ps.setString(2, prompt);
        ps.setBoolean(3, isLoginHintExists);
        rs = ps.executeQuery();
        while (rs.next()) {
            promptData.setScope(rs.getString("scope"));
            promptData.setLoginHintExists(rs.getBoolean("is_login_hint_exists"));
            promptData.setPromptValue(rs.getString("prompt_value"));
            promptData.setBehaviour(PromptData.behaviorTypes.valueOf(rs.getString("behaviour")));
        }
    } catch (SQLException ex) {
        handleException("Error while retrieving Propmt Data ", ex);
    } finally {
        IdentityDatabaseUtil.closeAllConnections(connection, rs, ps);
        return promptData;
    }
}

From source file:com.l2jfree.gameserver.model.entity.Couple.java

public void marry() {
    Connection con = null;/*from ww  w .ja  v a2 s  .  c o  m*/
    try {
        con = L2DatabaseFactory.getInstance().getConnection(con);
        PreparedStatement statement;

        statement = con.prepareStatement("UPDATE couples set maried = ?, weddingDate = ? where id = ?");
        statement.setBoolean(1, true);
        _weddingDate = System.currentTimeMillis();
        statement.setLong(2, _weddingDate);
        statement.setInt(3, _id);
        statement.execute();
        statement.close();
        _maried = true;
    } catch (Exception e) {
        _log.error("", e);
    } finally {
        L2DatabaseFactory.close(con);
    }
}

From source file:org.mskcc.cbio.portal.dao.DaoCancerStudy.java

/**
 * Adds a cancer study to the Database.//from w  w  w . j  av a  2  s. c o m
 * @param cancerStudy
 * @param overwrite if true, overwrite if exist.
 * @throws DaoException 
 */
public static void addCancerStudy(CancerStudy cancerStudy, boolean overwrite) throws DaoException {

    // make sure that cancerStudy refers to a valid TypeOfCancerId
    // TODO: have a foreign key constraint do this; why not?
    TypeOfCancer aTypeOfCancer = DaoTypeOfCancer.getTypeOfCancerById(cancerStudy.getTypeOfCancerId());
    if (null == aTypeOfCancer) {
        throw new DaoException("cancerStudy.getTypeOfCancerId() '" + cancerStudy.getTypeOfCancerId()
                + "' does not refer to a TypeOfCancer.");
    }

    // CANCER_STUDY_IDENTIFIER cannot be null
    String stableId = cancerStudy.getCancerStudyStableId();
    if (stableId == null) {
        throw new DaoException("Cancer study stable ID cannot be null.");
    }

    CancerStudy existing = getCancerStudyByStableId(stableId);
    if (existing != null) {
        if (overwrite) {
            //setStatus(Status.UNAVAILABLE, stableId);
            deleteCancerStudy(existing.getInternalId());
        } else {
            throw new DaoException("Cancer study " + stableId + "is already imported.");
        }
    }

    Connection con = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        con = JdbcUtil.getDbConnection(DaoCancerStudy.class);
        pstmt = con.prepareStatement(
                "INSERT INTO cancer_study " + "( `CANCER_STUDY_IDENTIFIER`, `NAME`, "
                        + "`DESCRIPTION`, `PUBLIC`, `TYPE_OF_CANCER_ID`, "
                        + "`PMID`, `CITATION`, `GROUPS`, `SHORT_NAME`, `STATUS` ) VALUES (?,?,?,?,?,?,?,?,?,?)",
                Statement.RETURN_GENERATED_KEYS);
        pstmt.setString(1, stableId);
        pstmt.setString(2, cancerStudy.getName());
        pstmt.setString(3, cancerStudy.getDescription());
        pstmt.setBoolean(4, cancerStudy.isPublicStudy());
        pstmt.setString(5, cancerStudy.getTypeOfCancerId());
        pstmt.setString(6, cancerStudy.getPmid());
        pstmt.setString(7, cancerStudy.getCitation());
        Set<String> groups = cancerStudy.getGroups();
        if (groups == null) {
            pstmt.setString(8, null);
        } else {
            pstmt.setString(8, StringUtils.join(groups, ";"));
        }
        pstmt.setString(9, cancerStudy.getShortName());
        //status is UNAVAILABLE until other data is loaded for this study. Once all is loaded, the 
        //data loading process can set this to AVAILABLE:
        //TODO - use this field in parts of the system that build up the list of studies to display in home page:
        pstmt.setInt(10, Status.UNAVAILABLE.ordinal());
        pstmt.executeUpdate();
        rs = pstmt.getGeneratedKeys();
        if (rs.next()) {
            int autoId = rs.getInt(1);
            cancerStudy.setInternalId(autoId);
        }

        cacheCancerStudy(cancerStudy, new java.util.Date());
    } catch (SQLException e) {
        throw new DaoException(e);
    } finally {
        JdbcUtil.closeAll(DaoCancerStudy.class, con, pstmt, rs);
    }

    reCacheAll();
}

From source file:net.sf.l2j.gameserver.model.entity.Couple.java

public void marry() {
    java.sql.Connection con = null;
    try {//from   w w  w.jav a2s  .c om
        con = L2DatabaseFactory.getInstance().getConnection();
        PreparedStatement statement;
        statement = con.prepareStatement("UPDATE couples set maried = ?, weddingDate = ? where id = ?");
        statement.setBoolean(1, true);
        _weddingDate = Calendar.getInstance();
        statement.setLong(2, _weddingDate.getTimeInMillis());
        statement.setInt(3, _Id);
        statement.execute();
        statement.close();
        _maried = true;
    } catch (Exception e) {
        _log.error("", e);
    } finally {
        try {
            con.close();
        } catch (Exception e) {
        }
    }
}

From source file:org.apache.phoenix.util.TestUtil.java

/**
 * @param conn//from w  w  w . jav  a 2  s.c  o  m
 *            connection to be used
 * @param sortOrder
 *            sort order of column contain input values
 * @param id
 *            id of the row being inserted
 * @param input
 *            input to be inserted
 */
public static void upsertRow(Connection conn, String tableName, String sortOrder, int id, Object input)
        throws SQLException {
    String dml = String.format("UPSERT INTO " + tableName + "_%s VALUES(?,?)", sortOrder);
    PreparedStatement stmt = conn.prepareStatement(dml);
    stmt.setInt(1, id);
    if (input instanceof String)
        stmt.setString(2, (String) input);
    else if (input instanceof Integer)
        stmt.setInt(2, (Integer) input);
    else if (input instanceof Double)
        stmt.setDouble(2, (Double) input);
    else if (input instanceof Float)
        stmt.setFloat(2, (Float) input);
    else if (input instanceof Boolean)
        stmt.setBoolean(2, (Boolean) input);
    else if (input instanceof Long)
        stmt.setLong(2, (Long) input);
    else
        throw new UnsupportedOperationException("" + input.getClass() + " is not supported by upsertRow");
    stmt.execute();
    conn.commit();
}

From source file:org.ulyssis.ipp.snapshot.Event.java

public void setRemoved(Connection connection, boolean removed) throws SQLException {
    if (!isRemovable()) {
        assert false; // This is a programming error
        return;/*  w  ww . j  a va 2s . c  o  m*/
    }
    PreparedStatement statement = connection
            .prepareStatement("UPDATE \"events\" SET \"removed\"=? WHERE \"id\"=?");
    statement.setBoolean(1, removed);
    statement.setLong(2, id);
    boolean result = statement.execute();
    assert (!result);
    this.removed = true;
}

From source file:de.whs.poodle.repositories.CourseRepository.java

public void create(Course course, String firstTermName) {
    try {//from   w  w  w  .  j ava  2  s.com
        int id = jdbc.query(con -> {
            // the function creates the course and the first term (firstTermId)
            PreparedStatement ps = con.prepareStatement("SELECT * FROM create_course(?,?,?,?,?,?,?)");
            ps.setInt(1, course.getInstructor().getId());
            ps.setString(2, course.getName());
            ps.setBoolean(3, course.getVisible());
            if (course.getPassword().trim().isEmpty())
                ps.setNull(4, Types.VARCHAR);
            else
                ps.setString(4, course.getPassword());

            Array otherInstructors = con.createArrayOf("int4", course.getOtherInstructorsIds().toArray());
            ps.setArray(5, otherInstructors);
            Array linkedCourses = con.createArrayOf("int4", course.getLinkedCoursesIds().toArray());
            ps.setArray(6, linkedCourses);
            ps.setString(7, firstTermName);
            return ps;
        }, new ResultSetExtractor<Integer>() {

            @Override
            public Integer extractData(ResultSet rs) throws SQLException, DataAccessException {
                rs.next();
                return rs.getInt(1);
            }
        });

        course.setId(id);
    } catch (DuplicateKeyException e) {
        throw new BadRequestException();
    }
}

From source file:org.apache.lucene.store.jdbc.lock.PhantomReadLock.java

public boolean obtain() {
    try {/*from   w  w  w .  j a va2s  .  c  o m*/
        if (jdbcDirectory.getDialect().useExistsBeforeInsertLock()) {
            // there are databases where the fact that an exception was thrown
            // invalidates the connection. So first we check if it exists, and
            // then insert it.
            if (jdbcDirectory.fileExists(name)) {
                return false;
            }
        }
        jdbcDirectory.getJdbcTemplate().executeUpdate(jdbcDirectory.getTable().sqlInsert(),
                new JdbcTemplate.PrepateStatementAwareCallback() {
                    public void fillPrepareStatement(PreparedStatement ps) throws Exception {
                        ps.setFetchSize(1);
                        ps.setString(1, name);
                        ps.setNull(2, Types.BLOB);
                        ps.setLong(3, 0);
                        ps.setBoolean(4, false);
                    }
                });
    } catch (Exception e) {
        if (log.isTraceEnabled()) {
            log.trace("Obtain Lock exception (might be valid) [" + e.getMessage() + "]");
        }
        return false;
    }
    return true;
}

From source file:de.nim.wscr.dao.MemberDAO.java

@Override
public void updateMember(Member member) {
    try {//from  w  w w .  j  av a 2  s  . co  m
        PreparedStatement statement = connection
                .prepareStatement("UPDATE db1.member SET FIRST_NAME = ?, LAST_NAME = ?, LICENSE = ?");
        statement.setString(1, member.getFirstName());
        statement.setString(2, member.getLastName());
        statement.setBoolean(3, member.getDriverLicense());
        statement.execute();

    } catch (SQLException e) {
        throw new RuntimeException(e);
    }
}

From source file:de.nim.wscr.dao.MemberDAO.java

@Override
public void addMember(Member member) {
    try {//  ww w.  j a  v a2 s. c  om
        PreparedStatement statement = connection
                .prepareStatement("INSERT INTO db1.member (FIRST_NAME, LAST_NAME, LICENSE) VALUES(?, ?, ?)");
        statement.setString(1, member.getFirstName());
        statement.setString(2, member.getLastName());
        statement.setBoolean(3, member.getDriverLicense());
        statement.execute();

    } catch (SQLException e) {
        throw new RuntimeException(e);
    }
}