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.flexive.core.storage.genericSQL.GenericBinarySQLOutputStream.java

/**
 * {@inheritDoc}/*  w  w  w .j av a2  s.c om*/
 */
@Override
public void run() {
    PreparedStatement ps = null;
    Connection con = null;
    try {
        con = Database.getNonTXDataSource(divisionId).getConnection();
        ps = con.prepareStatement("INSERT INTO " + DatabaseConst.TBL_BINARY_TRANSIT
                + " (BKEY,MIMETYPE,FBLOB,TFER_DONE,EXPIRE) VALUES(?,?,?,?,?)");
        ps.setString(1, handle);
        ps.setString(2, mimeType);
        ps.setBinaryStream(3, pipe, (int) expectedSize);
        ps.setBoolean(4, false);
        ps.setLong(5, System.currentTimeMillis() + ttl);
        long time = System.currentTimeMillis();
        ps.executeUpdate();
        if (LOG.isDebugEnabled())
            LOG.debug("Stored " + count + "/" + expectedSize + " bytes in "
                    + (System.currentTimeMillis() - time) + "[ms] in DB");
        try {
            pipe.close();
        } catch (IOException e) {
            LOG.error("IO error closing pipe: " + e.getMessage(), e);
        }
    } catch (SQLException e) {
        LOG.error("SQL error storing binary: " + e.getMessage(), e);
    } finally {
        Database.closeObjects(GenericBinarySQLOutputStream.class, con, ps);
    }
}

From source file:mupomat.controller.ObradaOperater.java

@Override
public void promjeniPostojeci(Operater entitet) {
    try {//from www. j av  a  2  s . co m
        Connection veza = MySqlBazaPodataka.getConnection();
        PreparedStatement izraz = null;
        if (entitet.getLozinka().length() > 0) {
            izraz = veza
                    .prepareStatement("update operater set lozinka=?,ime=?,prezime=?,aktivan=? where sifra=? ");

            izraz.setString(1, DigestUtils.md5Hex(entitet.getLozinka()));
            izraz.setString(2, entitet.getIme());
            izraz.setString(3, entitet.getPrezime());
            izraz.setBoolean(4, entitet.isAktivan());
            izraz.setInt(5, entitet.getSifra());
            izraz.executeUpdate();
        } else {
            izraz = veza.prepareStatement("update operater set  ime=?,prezime=?,aktivan=? where sifra=? ");

            izraz.setString(1, entitet.getIme());
            izraz.setString(2, entitet.getPrezime());
            izraz.setBoolean(3, entitet.isAktivan());
            izraz.setInt(4, entitet.getSifra());
            izraz.executeUpdate();
        }
        izraz.close();
        veza.close();
    } catch (Exception e) {
        //  System.out.println(e.getMessage());
        e.printStackTrace();
        return;
    }
}

From source file:com.alfaariss.oa.authentication.remote.aselect.idp.storage.jdbc.IDPJDBCStorage.java

/**
 * @see com.alfaariss.oa.engine.core.idp.storage.IIDPStorage#getIDP(java.lang.String)
 *///from   w  w  w . ja  v a 2  s  .  com
public IIDP getIDP(String id) throws OAException {
    Connection connection = null;
    PreparedStatement pSelect = null;
    ResultSet resultSet = null;
    ASelectIDP oASelectIDP = null;
    try {
        connection = _dataSource.getConnection();

        pSelect = connection.prepareStatement(_querySelect);
        pSelect.setBoolean(1, true);
        pSelect.setString(2, id);
        resultSet = pSelect.executeQuery();
        if (resultSet.next()) {
            oASelectIDP = new ASelectIDP(resultSet.getString(COLUMN_ID),
                    resultSet.getString(COLUMN_FRIENDLYNAME), resultSet.getString(COLUMN_SERVER_ID),
                    resultSet.getString(COLUMN_URL), resultSet.getInt(COLUMN_LEVEL),
                    resultSet.getBoolean(COLUMN_SIGNING), resultSet.getString(COLUMN_COUNTRY),
                    resultSet.getString(COLUMN_LANGUAGE), resultSet.getBoolean(COLUMN_ASYNCHRONOUS_LOGOUT),
                    resultSet.getBoolean(COLUMN_SYNCHRONOUS_LOGOUT),
                    resultSet.getBoolean(COLUMN_SEND_ARP_TARGET));
        }
    } catch (Exception e) {
        _logger.fatal("Internal error during retrieval of IDP with id: " + id, e);
        throw new OAException(SystemErrors.ERROR_INTERNAL);
    } finally {
        try {
            if (pSelect != null)
                pSelect.close();
        } catch (Exception e) {
            _logger.error("Could not close select statement", e);
        }

        try {
            if (connection != null)
                connection.close();
        } catch (Exception e) {
            _logger.error("Could not close connection", e);
        }
    }
    return oASelectIDP;
}

From source file:org.apache.lucene.store.jdbc.index.AbstractJdbcIndexOutput.java

public void close() throws IOException {
    super.close();
    final long length = length();
    doBeforeClose();//from ww w . ja va  2 s .co m
    jdbcDirectory.getJdbcTemplate().update(jdbcDirectory.getTable().sqlInsert(), new PreparedStatementSetter() {
        @Override
        public void setValues(PreparedStatement ps) throws SQLException {
            ps.setFetchSize(1);
            ps.setString(1, name);
            InputStream is = null;
            try {
                is = openInputStream();
                if (jdbcDirectory.getDialect().useInputStreamToInsertBlob()) {
                    ps.setBinaryStream(2, is, (int) length());
                } else {
                    ps.setBlob(2, new InputStreamBlob(is, length));
                }
                ps.setLong(3, length);
                ps.setBoolean(4, false);
            } catch (IOException e) {
                throw new SQLException(e);
            }
        }
    });
    doAfterClose();
}

From source file:org.schedoscope.metascope.tasks.repository.jdbc.impl.TableEntityJdbcRepository.java

public void savePartial(Connection connection, TableEntity tableEntity) {
    String insertTableSql = "insert into table_entity (table_fqdn, table_name, database_name, url_path_prefix, external_table, "
            + "table_description, storage_format, materialize_once, transformation_type, status) "
            + "values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
    PreparedStatement stmt = null;
    try {//  w  w w .j av  a2  s.  com
        stmt = connection.prepareStatement(insertTableSql);
        stmt.setString(1, tableEntity.getFqdn());
        stmt.setString(2, tableEntity.getTableName());
        stmt.setString(3, tableEntity.getDatabaseName());
        stmt.setString(4, tableEntity.getUrlPathPrefix());
        stmt.setBoolean(5, tableEntity.isExternalTable());
        stmt.setString(6, tableEntity.getTableDescription());
        stmt.setString(7, tableEntity.getStorageFormat());
        stmt.setBoolean(8, tableEntity.isMaterializeOnce());
        stmt.setString(9, tableEntity.getTransformationType());
        stmt.setString(10, tableEntity.getStatus());
        stmt.execute();
    } catch (SQLException e) {
        LOG.error("Could not save table", e);
    } finally {
        DbUtils.closeQuietly(stmt);
    }
}

From source file:org.schedoscope.metascope.tasks.repository.jdbc.impl.TableEntityJdbcRepository.java

public void updatePartial(Connection connection, TableEntity tableEntity) {
    String insertTableSql = "update table_entity set table_fqdn=?, table_name=?, database_name=?, url_path_prefix=?, "
            + "external_table=?, table_description=?, storage_format=?, materialize_once=?, transformation_type=?, status=?"
            + "where " + TableEntity.TABLE_FQDN + " = ?";
    PreparedStatement stmt = null;
    try {/*from ww  w .ja v  a 2s .c om*/
        stmt = connection.prepareStatement(insertTableSql);
        stmt.setString(1, tableEntity.getFqdn());
        stmt.setString(2, tableEntity.getTableName());
        stmt.setString(3, tableEntity.getDatabaseName());
        stmt.setString(4, tableEntity.getUrlPathPrefix());
        stmt.setBoolean(5, tableEntity.isExternalTable());
        stmt.setString(6, tableEntity.getTableDescription());
        stmt.setString(7, tableEntity.getStorageFormat());
        stmt.setBoolean(8, tableEntity.isMaterializeOnce());
        stmt.setString(9, tableEntity.getTransformationType());
        stmt.setString(10, tableEntity.getStatus());
        stmt.setString(11, tableEntity.getFqdn());
        stmt.execute();
    } catch (SQLException e) {
        LOG.error("Could not save table", e);
    } finally {
        DbUtils.closeQuietly(stmt);
    }
}

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

public int createMcWorksheet(CreateMcWorksheetForm form, int studentId, int courseTermId) {
    return jdbc.query(con -> {
        PreparedStatement ps = con.prepareStatement("SELECT * FROM generate_student_mc_worksheet(?,?,?,?,?)");
        ps.setInt(1, courseTermId);/*from   w  w w . jav a 2 s.co  m*/
        ps.setInt(2, studentId);

        Array tagsArray = con.createArrayOf("int4", ObjectUtils.toObjectArray(form.getTags()));
        ps.setArray(3, tagsArray);

        ps.setInt(4, form.getMaximum());
        ps.setBoolean(5, form.isIgnoreAlreadyAnswered());

        return ps;
    }, new ResultSetExtractor<Integer>() {

        @Override
        public Integer extractData(ResultSet rs) throws SQLException, DataAccessException {
            if (!rs.next()) // no results -> generated worksheet had no questions
                return 0;

            return rs.getInt("id");
        }
    });
}

From source file:org.obiba.onyx.jade.instrument.reichert.OraInstrumentRunner.java

/**
 * Retrieve participant data from the database and write them in the patient scan database
 * //from  www.ja va  2  s .c  o  m
 * @throws Exception
 */
private void initializeParticipantData() {
    log.info("initializing participant Data");

    jdbc.update("insert into Patients ( Name, BirthDate, Sex, GroupID, ID, RaceID ) values( ?, ?, ?, ?, ?, ? )",
            new PreparedStatementSetter() {

                @Override
                public void setValues(PreparedStatement ps) throws SQLException {
                    ps.setString(1, instrumentExecutionService.getParticipantLastName() + ", "
                            + instrumentExecutionService.getParticipantFirstName());
                    ps.setDate(2,
                            new java.sql.Date(instrumentExecutionService.getParticipantBirthDate().getTime()));
                    ps.setBoolean(3, instrumentExecutionService.getParticipantGender().startsWith("M"));
                    ps.setInt(4, 2);
                    ps.setInt(5, id);
                    ps.setInt(6, 1);
                }
            });
}

From source file:dk.netarkivet.harvester.datamodel.GlobalCrawlerTrapListDBDAO.java

/**
 * Update a trap list. In order to update the trap expressions for this
 * list, we first delete all the existing trap expressions for the list
 * then add all those in the updated version.
 * @param trapList the trap list to update
 *//* w  w  w . ja  v a2s. co m*/
@Override
public void update(GlobalCrawlerTrapList trapList) {
    ArgumentNotValid.checkNotNull(trapList, "trapList");
    Connection conn = HarvestDBConnection.get();
    PreparedStatement stmt = null;
    try {
        conn.setAutoCommit(false);
        stmt = conn.prepareStatement(LIST_UPDATE_STMT);
        stmt.setString(1, trapList.getName());
        stmt.setString(2, trapList.getDescription());
        stmt.setBoolean(3, trapList.isActive());
        stmt.setInt(4, trapList.getId());
        stmt.executeUpdate();
        stmt.close();

        //Delete all the trap expressions.
        stmt = conn.prepareStatement(DELETE_EXPR_STMT);
        stmt.setInt(1, trapList.getId());
        stmt.executeUpdate();
        stmt.close();
        // Add the new trap expressions one by one.
        for (String expr : trapList.getTraps()) {
            stmt = conn.prepareStatement(INSERT_TRAP_EXPR_STMT);
            stmt.setInt(1, trapList.getId());
            stmt.setString(2, expr);
            stmt.executeUpdate();
            stmt.close();
        }
        conn.commit();
    } catch (SQLException e) {
        String message = "Error updating trap list :'" + trapList.getId() + "'\n"
                + ExceptionUtils.getSQLExceptionCause(e);
        log.warn(message, e);
        throw new UnknownID(message, e);
    } finally {
        DBUtils.closeStatementIfOpen(stmt);
        DBUtils.rollbackIfNeeded(conn, "update trap list", trapList);
        HarvestDBConnection.release(conn);
    }
}

From source file:fll.web.playoff.JsonBracketDataTests.java

private void insertScore(final Connection connection, final int team, final int run, final boolean verified,
        final double score) throws SQLException {
    PreparedStatement ps = null;
    try {//from  www  . ja  v a2s .  c  om
        ps = connection.prepareStatement(
                "INSERT INTO Performance (TeamNumber, Tournament, RunNumber, NoShow, Bye, Verified, Score, ComputedTotal)"
                        + " VALUES (?, 2, ?, false, false, ?, ?, ?)");
        ps.setInt(1, team);
        ps.setInt(2, run);
        ps.setBoolean(3, verified);
        ps.setDouble(4, score);
        ps.setDouble(5, score);
        Assert.assertEquals(1, ps.executeUpdate());
    } finally {
        SQLFunctions.close(ps);
    }
}