List of usage examples for java.sql PreparedStatement setBoolean
void setBoolean(int parameterIndex, boolean x) throws SQLException;
boolean
value. From source file:com.wabacus.system.datatype.BooleanType.java
public void setPreparedStatementValue(int iindex, String value, PreparedStatement pstmt, AbsDatabaseType dbtype) throws SQLException { log.debug("setBoolean(" + iindex + "," + value + ")"); pstmt.setBoolean(iindex, (Boolean) label2value(value)); }
From source file:com.useekm.indexing.postgis.IndexedStatement.java
public static void addNewBatch(PreparedStatement stat, IndexedStatement indexedStatement) throws SQLException { int idx = 1;//from w w w . j a v a 2 s . com if (indexedStatement.objectDate != null) stat.setDate(idx++, new java.sql.Date(indexedStatement.objectDate.getTime())); else stat.setDate(idx++, null); stat.setString(idx++, indexedStatement.objectLanguage); stat.setObject(idx++, indexedStatement.objectSpatial); stat.setString(idx++, indexedStatement.objectString); stat.setString(idx++, indexedStatement.objectTsVectorConfig); stat.setString(idx++, indexedStatement.objectType); stat.setBoolean(idx++, indexedStatement.objectUri); stat.setString(idx++, indexedStatement.predicate); stat.setString(idx++, indexedStatement.subject); stat.addBatch(); }
From source file:at.alladin.rmbt.db.fields.BooleanField.java
@Override public void getField(final PreparedStatement ps, final int idx) throws SQLException { if (value == null) ps.setNull(idx, Types.BOOLEAN); else/*from w ww . ja v a 2 s. c o m*/ ps.setBoolean(idx, value); }
From source file:org.mskcc.cbio.cgds.dao.DaoGistic.java
public static void addGistic(Gistic gistic) throws DaoException, validationException { if (gistic == null) { throw new DaoException("Given a null gistic object"); }//from www . ja v a 2 s . c o m Connection con = null; PreparedStatement pstmt = null; ResultSet rs = null; ValidateGistic.validateBean(gistic); try { con = JdbcUtil.getDbConnection(DaoGistic.class); // insert into SQL gistic table pstmt = con.prepareStatement("INSERT INTO gistic (`CANCER_STUDY_ID`," + "`CHROMOSOME`, " + "`CYTOBAND`, " + "`WIDE_PEAK_START`, " + "`WIDE_PEAK_END`, " + "`Q_VALUE`, " + "`AMP`) " + "VALUES (?,?,?,?,?,?,?)", Statement.RETURN_GENERATED_KEYS); pstmt.setInt(1, gistic.getCancerStudyId()); pstmt.setInt(2, gistic.getChromosome()); pstmt.setString(3, gistic.getCytoband()); pstmt.setInt(4, gistic.getPeakStart()); pstmt.setInt(5, gistic.getPeakEnd()); pstmt.setDouble(6, gistic.getqValue()); pstmt.setBoolean(7, gistic.getAmp()); pstmt.executeUpdate(); // insert into SQL gistic_to_gene table rs = pstmt.getGeneratedKeys(); if (rs.next()) { int autoId = rs.getInt(1); gistic.setInternalId(autoId); } addGisticGenes(gistic, con); } catch (SQLException e) { throw new DaoException(e); } finally { JdbcUtil.closeAll(DaoGistic.class, con, pstmt, rs); } }
From source file:org.forumj.dbextreme.db.dao.FJIpAddressDao.java
public void create(IFJIpAddress ipAddress) throws SQLException, ConfigurationException, IOException { String query = getCreateIpAddressQuery(); Connection conn = null;//w ww . j a v a 2s . com PreparedStatement st = null; try { conn = getConnection(); st = conn.prepareStatement(query); st.setString(1, ipAddress.getIp()); st.setBoolean(2, ipAddress.isSpammer()); st.setString(3, ipAddress.getSource()); st.setTimestamp(4, new java.sql.Timestamp(ipAddress.getLastCheck().getTime())); st.executeUpdate(); } finally { readFinally(conn, st); } }
From source file:org.forumj.dbextreme.db.dao.FJIpAddressDao.java
public void update(IFJIpAddress ipAddress) throws IOException, ConfigurationException, SQLException { String query = getUpdateIpAddressQuery(); Connection conn = null;/*w w w . j ava 2 s .c om*/ PreparedStatement st = null; try { conn = getConnection(); st = conn.prepareStatement(query); st.setString(1, ipAddress.getIp()); st.setBoolean(2, ipAddress.isSpammer()); st.setString(3, ipAddress.getSource()); st.setTimestamp(4, new java.sql.Timestamp(ipAddress.getLastCheck().getTime())); st.setLong(5, ipAddress.getId()); st.executeUpdate(); } finally { readFinally(conn, st); } }
From source file:com.onclave.testbench.jdbcTemplate.DAOSupport.StudentDAOImplementation.java
@Override public boolean changeActivityStatusOfStudent(final long idStudent, final boolean activityStatus) { final int result = jdbcTemplate.update(new PreparedStatementCreator() { @Override/*from w w w . j a v a 2 s . co m*/ public PreparedStatement createPreparedStatement(Connection connection) throws SQLException { PreparedStatement preparedStatement = connection .prepareStatement(QueryStatements.UPDATE_STUDENT_ACTIVITY_SQL); preparedStatement.setBoolean(1, activityStatus); preparedStatement.setLong(2, idStudent); return preparedStatement; } }); if (result > 0) { return true; } return false; }
From source file:com.tethrnet.manage.db.PublicKeyDB.java
/** * returns public keys based on sort order defined * * @param sortedSet object that defines sort order * @return sorted script list/*from w ww . j av a 2 s.c om*/ */ public static SortedSet getPublicKeySet(SortedSet sortedSet) { ArrayList<PublicKey> publicKeysList = new ArrayList<PublicKey>(); String orderBy = ""; if (sortedSet.getOrderByField() != null && !sortedSet.getOrderByField().trim().equals("")) { orderBy = " order by " + sortedSet.getOrderByField() + " " + sortedSet.getOrderByDirection(); } String sql = "select p.*, u.username from public_keys p, users u where u.id=p.user_id "; sql += StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_USER_ID)) ? " and p.user_id=? " : ""; sql += StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_PROFILE_ID)) ? " and p.profile_id=? " : ""; sql += StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_ENABLED)) ? " and p.enabled=? " : " and p.enabled=true"; sql = sql + orderBy; Connection con = null; try { con = DBUtils.getConn(); PreparedStatement stmt = con.prepareStatement(sql); int i = 1; //set filters in prepared statement if (StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_USER_ID))) { stmt.setLong(i++, Long.valueOf(sortedSet.getFilterMap().get(FILTER_BY_USER_ID))); } if (StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_PROFILE_ID))) { stmt.setLong(i++, Long.valueOf(sortedSet.getFilterMap().get(FILTER_BY_PROFILE_ID))); } if (StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_ENABLED))) { stmt.setBoolean(i++, Boolean.valueOf(sortedSet.getFilterMap().get(FILTER_BY_ENABLED))); } ResultSet rs = stmt.executeQuery(); while (rs.next()) { PublicKey publicKey = new PublicKey(); publicKey.setId(rs.getLong("id")); publicKey.setKeyNm(rs.getString("key_nm")); publicKey.setPublicKey(rs.getString("public_key")); publicKey.setProfile(ProfileDB.getProfile(con, rs.getLong("profile_id"))); publicKey.setType(SSHUtil.getKeyType(publicKey.getPublicKey())); publicKey.setFingerprint(SSHUtil.getFingerprint(publicKey.getPublicKey())); publicKey.setCreateDt(rs.getTimestamp("create_dt")); publicKey.setUsername(rs.getString("username")); publicKey.setUserId(rs.getLong("user_id")); publicKey.setEnabled(rs.getBoolean("enabled")); publicKeysList.add(publicKey); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } DBUtils.closeConn(con); sortedSet.setItemList(publicKeysList); return sortedSet; }
From source file:com.keybox.manage.db.PublicKeyDB.java
/** * returns public keys based on sort order defined * * @param sortedSet object that defines sort order * @return sorted script list// w w w. j a v a2s . c om */ public static SortedSet getPublicKeySet(SortedSet sortedSet) { ArrayList<PublicKey> publicKeysList = new ArrayList<>(); String orderBy = ""; if (sortedSet.getOrderByField() != null && !sortedSet.getOrderByField().trim().equals("")) { orderBy = " order by " + sortedSet.getOrderByField() + " " + sortedSet.getOrderByDirection(); } String sql = "select p.*, u.username from public_keys p, users u where u.id=p.user_id "; sql += StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_USER_ID)) ? " and p.user_id=? " : ""; sql += StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_PROFILE_ID)) ? " and p.profile_id=? " : ""; sql += StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_ENABLED)) ? " and p.enabled=? " : " and p.enabled=true"; sql = sql + orderBy; Connection con = null; try { con = DBUtils.getConn(); PreparedStatement stmt = con.prepareStatement(sql); int i = 1; //set filters in prepared statement if (StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_USER_ID))) { stmt.setLong(i++, Long.valueOf(sortedSet.getFilterMap().get(FILTER_BY_USER_ID))); } if (StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_PROFILE_ID))) { stmt.setLong(i++, Long.valueOf(sortedSet.getFilterMap().get(FILTER_BY_PROFILE_ID))); } if (StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_ENABLED))) { stmt.setBoolean(i, Boolean.valueOf(sortedSet.getFilterMap().get(FILTER_BY_ENABLED))); } ResultSet rs = stmt.executeQuery(); while (rs.next()) { PublicKey publicKey = new PublicKey(); publicKey.setId(rs.getLong("id")); publicKey.setKeyNm(rs.getString(KEY_NM)); publicKey.setPublicKey(rs.getString(PUBLIC_KEY)); publicKey.setProfile(ProfileDB.getProfile(con, rs.getLong(PROFILE_ID))); publicKey.setType(SSHUtil.getKeyType(publicKey.getPublicKey())); publicKey.setFingerprint(SSHUtil.getFingerprint(publicKey.getPublicKey())); publicKey.setCreateDt(rs.getTimestamp(CREATE_DT)); publicKey.setUsername(rs.getString("username")); publicKey.setUserId(rs.getLong("user_id")); publicKey.setEnabled(rs.getBoolean("enabled")); publicKeysList.add(publicKey); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } DBUtils.closeConn(con); sortedSet.setItemList(publicKeysList); return sortedSet; }
From source file:org.LexGrid.util.sql.DBUtility.java
/** * Sets booleans properly in the LexGrid world. * /*from ww w. j a v a 2 s . c o m*/ * @param statement * @param colNumber * @param value * @param isSqlLite * - using sqlLite tables? Set to true if the answer is yes. * @param databaseType * - optional. Set to null or "" if you don't know it. * @throws SQLException */ public static void setBooleanOnPreparedStatment(PreparedStatement statement, int colNumber, Boolean value, boolean isSqlLite, String databaseType) throws SQLException { if (databaseType == null || databaseType.length() == 0) { databaseType = statement.getConnection().getMetaData().getDatabaseProductName(); } // This has been tested (and works correctly) on mysql (using tinyint // with 1 and 0), postgres (using // bool) // and Access using both a Text of (True or False) and yes/no. if (value == null) { // mysql lite (on access) uses yesno's for booleans (which don't // support null), while regular sql // doesn't. if (isSqlLite && databaseType.equals("ACCESS")) { statement.setBoolean(colNumber, false); } // the new postgres driver doesn't allow you to use the setString to // null trick. else if (databaseType.equals("PostgreSQL")) { statement.setNull(colNumber, java.sql.Types.BOOLEAN); } // most other databases let you set null on a string, even if it // isn't a string type. else { statement.setString(colNumber, null); } } else { // sql on format on access, and mysql both use strings instead of // booleans (to support null) if ((databaseType.equals("ACCESS") && !isSqlLite)) { statement.setString(colNumber, value.booleanValue() + ""); } else if (databaseType.equals("MySQL")) { statement.setInt(colNumber, (value.booleanValue() ? 1 : 0)); } else { statement.setBoolean(colNumber, value.booleanValue()); } } }