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:org.schedoscope.metascope.tasks.repository.mysql.impl.FieldEntityMySQLRepository.java

@Override
public void insertOrUpdate(Connection connection, List<FieldEntity> fields) {
    String insertFieldSql = "insert into field_entity ("
            + JDBCUtil.getDatabaseColumnsForClass(FieldEntity.class) + ") values ("
            + JDBCUtil.getValuesCountForClass(FieldEntity.class) + ") " + "on duplicate key update "
            + MySQLUtil.getOnDuplicateKeyString(FieldEntity.class);
    PreparedStatement stmt = null;
    try {//from w w  w .j  ava  2s .  co  m
        int batch = 0;
        connection.setAutoCommit(false);
        stmt = connection.prepareStatement(insertFieldSql);
        for (FieldEntity fieldEntity : fields) {
            stmt.setString(1, fieldEntity.getFqdn());
            stmt.setString(2, fieldEntity.getName());
            stmt.setString(3, fieldEntity.getType());
            stmt.setString(4, fieldEntity.getDescription());
            stmt.setInt(5, fieldEntity.getFieldOrder());
            stmt.setBoolean(6, fieldEntity.isParameterField());
            stmt.setString(7, fieldEntity.getFqdn());
            stmt.addBatch();
            batch++;
            if (batch % 1024 == 0) {
                stmt.executeBatch();
            }
        }
        stmt.executeBatch();
        connection.commit();
        connection.setAutoCommit(true);
    } catch (SQLException e) {
        LOG.error("Could not save field", e);
    } finally {
        DbUtils.closeQuietly(stmt);
    }
}

From source file:mupomat.controller.ObradaOperater.java

@Override
public Operater dodajNovi(Operater entitet) {
    try {/* w ww.  java  2s .  c o m*/
        Connection veza = MySqlBazaPodataka.getConnection();
        PreparedStatement izraz = veza.prepareStatement(
                "insert into operater (korisnickoime,lozinka,ime,prezime,aktivan) values (?,?,?,?,?)",
                Statement.RETURN_GENERATED_KEYS);
        izraz.setString(1, entitet.getKorisnickoIme());
        izraz.setString(2, DigestUtils.md5Hex(entitet.getLozinka()));
        izraz.setString(3, entitet.getIme());
        izraz.setString(4, entitet.getPrezime());
        izraz.setBoolean(5, entitet.isAktivan());
        izraz.executeUpdate();
        ResultSet rs = izraz.getGeneratedKeys();
        rs.next();
        entitet.setSifra(rs.getInt(1));
        rs.close();
        izraz.close();
        veza.close();
    } catch (Exception e) {
        //  System.out.println(e.getMessage());
        e.printStackTrace();
        return null;
    }
    return entitet;
}

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

/**
 * @see com.alfaariss.oa.engine.core.idp.storage.IIDPStorage#getAll()
 *//*  w  w w  . j  a  v a2  s  . c  o m*/
public List<IIDP> getAll() throws OAException {
    Connection connection = null;
    PreparedStatement pSelect = null;
    ResultSet resultSet = null;
    List<IIDP> listIDPs = new Vector<IIDP>();
    try {
        connection = _dataSource.getConnection();

        pSelect = connection.prepareStatement(_querySelectAll);
        pSelect.setBoolean(1, true);
        resultSet = pSelect.executeQuery();
        while (resultSet.next()) {
            ASelectIDP idp = 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));
            listIDPs.add(idp);
        }
    } catch (Exception e) {
        _logger.fatal("Internal error during retrieval of all IDPs", 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 listIDPs;
}

From source file:com.concursive.connect.web.webdav.WebdavManager.java

/**
 * used by basic authentication scheme/*  w  ww  . j  a va  2 s . co  m*/
 *
 * @param db       Description of the Parameter
 * @param username Description of the Parameter
 * @param password Description of the Parameter
 * @return Description of the Return Value
 * @throws SQLException Description of the Exception
 */
public boolean allowUser(Connection db, String username, String password) throws SQLException {
    boolean status = false;
    PreparedStatement pst = db.prepareStatement("SELECT password, expiration, user_id " + "FROM users "
            + "WHERE username = ? " + "AND enabled = ? ");
    pst.setString(1, username);
    pst.setBoolean(2, true);
    ResultSet rs = pst.executeQuery();
    if (rs.next()) {
        //TODO: determine if the user account has not expired
        String pw = rs.getString("password");
        if (pw.equals(PasswordHash.encrypt(password))) {
            int userId = rs.getInt("user_id");
            int roleId = -1;
            WebdavUser user = new WebdavUser();
            user.setUserId(userId);
            user.setRoleId(roleId);
            users.put(username.toLowerCase(), user);
            status = true;
        }
    }
    rs.close();
    pst.close();
    return status;
}

From source file:com.ewcms.component.interaction.dao.InteractionDAO.java

@Override
public void addSpeak(final Speak vo) {
    final String sql = "Insert Into plugin_interaction_speak "
            + "(username,content,checked,interaction_id,ip,name) " + "Values (?,?,?,?,?,?)";

    jdbcTemplate.update(new PreparedStatementCreator() {

        @Override//from ww w .  j  av  a2s  .co  m
        public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
            PreparedStatement ps = con.prepareStatement(sql);
            ps.setString(1, vo.getUsername());
            ps.setString(2, vo.getContent());
            ps.setBoolean(3, vo.getChecked());
            ps.setInt(4, vo.getInteractionId());
            ps.setString(5, vo.getIp());
            ps.setString(6, vo.getName());

            return ps;
        }
    });
}

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

@Override
public void save(Connection connection, TableEntity tableEntity) {
    String insertTableSql = "insert into table_entity ("
            + JDBCUtil.getDatabaseColumnsForClass(TableEntity.class) + ") values ("
            + JDBCUtil.getValuesCountForClass(TableEntity.class) + ")";
    PreparedStatement stmt = null;
    try {//from  www  .  jav a  2 s .  co m
        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.setString(8, tableEntity.getInputFormat());
        stmt.setString(9, tableEntity.getOutputFormat());
        stmt.setBoolean(10, tableEntity.isMaterializeOnce());
        stmt.setLong(11, tableEntity.getCreatedAt());
        stmt.setString(12, tableEntity.getStatus());
        stmt.setString(13, tableEntity.getTableOwner());
        stmt.setString(14, tableEntity.getDataPath());
        stmt.setLong(15, tableEntity.getDataSize());
        stmt.setString(16, tableEntity.getPermissions());
        stmt.setLong(17, tableEntity.getRowcount());
        stmt.setString(18, tableEntity.getTransformationType());
        stmt.setString(19, tableEntity.getLastData());
        stmt.setString(20, tableEntity.getTimestampField());
        stmt.setString(21, tableEntity.getTimestampFieldFormat());
        stmt.setLong(22, tableEntity.getLastChange());
        stmt.setLong(23, tableEntity.getLastPartitionCreated());
        stmt.setLong(24, tableEntity.getLastSchemaChange());
        stmt.setLong(25, tableEntity.getLastTransformation());
        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

@Override
public void update(Connection connection, TableEntity tableEntity) {
    String updateTableSql = "update table_entity set " + JDBCUtil.getSetExpressionForClass(TableEntity.class)
            + " where " + TableEntity.TABLE_FQDN + " = ?";
    PreparedStatement stmt = null;
    try {/*from w  ww .  j a  va  2s . c om*/
        stmt = connection.prepareStatement(updateTableSql);
        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.setString(8, tableEntity.getInputFormat());
        stmt.setString(9, tableEntity.getOutputFormat());
        stmt.setBoolean(10, tableEntity.isMaterializeOnce());
        stmt.setLong(11, tableEntity.getCreatedAt());
        stmt.setString(12, tableEntity.getStatus());
        stmt.setString(13, tableEntity.getTableOwner());
        stmt.setString(14, tableEntity.getDataPath());
        stmt.setLong(15, tableEntity.getDataSize());
        stmt.setString(16, tableEntity.getPermissions());
        stmt.setLong(17, tableEntity.getRowcount());
        stmt.setString(18, tableEntity.getTransformationType());
        stmt.setString(19, tableEntity.getLastData());
        stmt.setString(20, tableEntity.getTimestampField());
        stmt.setString(21, tableEntity.getTimestampFieldFormat());
        stmt.setLong(22, tableEntity.getLastChange());
        stmt.setLong(23, tableEntity.getLastPartitionCreated());
        stmt.setLong(24, tableEntity.getLastSchemaChange());
        stmt.setLong(25, tableEntity.getLastTransformation());
        stmt.setString(26, tableEntity.getFqdn());
        stmt.execute();
    } catch (SQLException e) {
        LOG.error("Could not update table", e);
    } finally {
        DbUtils.closeQuietly(stmt);
    }
}

From source file:br.inpe.XSDMiner.MineXSD.java

@Override
public void process(SCMRepository repo, Commit commit, PersistenceMechanism writer) {

    String projectName = "";
    String fullName = "";

    try {/*  w w  w . j  a va 2s .c om*/
        if (!commit.getBranches().contains("master"))
            return;

        if (commit.isMerge())
            return;

        Class.forName("org.postgresql.Driver");
        projectName = repo.getPath().substring(repo.getPath().lastIndexOf("/") + 1);

        for (Modification m : commit.getModifications()) {
            String fName = m.getFileName();
            String addrem = "";
            String fullNameNew = m.getNewPath();
            String fullNameOld = m.getOldPath();
            if (fullNameNew.equals("/dev/null")) {
                addrem = "r";
                fullName = fullNameOld;
            } else {
                fullName = fullNameNew;
            }

            if (fullNameOld.equals("/dev/null")) {
                addrem = "a";
            }

            String fileExtension = fName.substring(fName.lastIndexOf(".") + 1);

            boolean isWSDL = fileExtension.equals("wsdl");
            boolean isXSD = fileExtension.equals("xsd");

            if (!(isWSDL || isXSD))
                continue;

            InputStream input = new ByteArrayInputStream(m.getSourceCode().getBytes(StandardCharsets.UTF_8));
            ByteArrayOutputStream outputXSD = new ByteArrayOutputStream();

            String[] schemas;
            if (fileExtension.equals("wsdl")) {
                XSDExtractor.wsdlToXSD(input, outputXSD);
                schemas = XSDExtractor.splitXSD(outputXSD.toString());

            } else {
                outputXSD.write(IOUtils.toString(input).getBytes());
                schemas = new String[1];
                schemas[0] = outputXSD.toString();
            }

            String url = "jdbc:postgresql://localhost/xsdminer";
            Properties props = new Properties();
            props.setProperty("user", "postgres");
            props.setProperty("password", "070910");
            Connection conn = DriverManager.getConnection(url, props);

            int schemaCount = schemas.length;

            for (int i = 0; i < schemaCount; i++) {
                String query = "INSERT INTO files VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
                PreparedStatement st = conn.prepareStatement(query);
                st.setInt(1, i + 1);
                st.setString(2, fullName);
                st.setString(3, projectName);
                st.setString(4, commit.getHash());
                st.setTimestamp(5, new java.sql.Timestamp(commit.getDate().getTimeInMillis()));
                st.setString(6, schemas[i]);
                st.setString(7, addrem);
                st.setBoolean(8, false);
                st.executeUpdate();
                st.close();
            }
            conn.close();
        }
    } catch (IOException ex) {
        Logger.getLogger(MineXSD.class.getName()).log(Level.SEVERE, null, ex);
    } catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        System.out.println("Failure - Project " + projectName + "; file: " + fullName);
        //e.printStackTrace();
    } finally {
        repo.getScm().reset();
    }
}

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

public int getCountForMcWorksheet(CreateMcWorksheetForm form, int studentId, int courseTermId) {
    return jdbc.query(con -> {
        PreparedStatement ps = con
                .prepareStatement("SELECT COUNT(*) AS count FROM get_mc_questions_for_worksheet(?,?,?,?,?)");
        ps.setInt(1, courseTermId);/*from   w  ww . 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 {
            rs.next();
            return rs.getInt("count");
        }

    });
}

From source file:com.tascape.reactor.report.MySqlBaseBean.java

public void setSuiteResultInvisible(String srid, boolean invisible) throws NamingException, SQLException {
    String sql = "UPDATE " + SuiteResult.TABLE_NAME + " SET " + SuiteResult.INVISIBLE_ENTRY + " = ?" + " WHERE "
            + SuiteResult.SUITE_RESULT_ID + " = ?;";
    try (Connection conn = this.getConnection()) {
        PreparedStatement stmt = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_SENSITIVE,
                ResultSet.CONCUR_UPDATABLE);
        stmt.setBoolean(1, invisible);
        stmt.setString(2, srid);/*w  ww.j  a  v a 2 s . c  om*/
        LOG.trace("{}", stmt);
        stmt.executeUpdate();
    }
}