List of usage examples for java.sql PreparedStatement setBoolean
void setBoolean(int parameterIndex, boolean x) throws SQLException;
boolean
value. From source file:com.sf.ddao.factory.param.ParameterHelper.java
public static void bind(PreparedStatement preparedStatement, int idx, Object param, Class<?> clazz, Context context) throws SQLException { if (clazz == Integer.class || clazz == Integer.TYPE) { preparedStatement.setInt(idx, (Integer) param); } else if (clazz == String.class) { preparedStatement.setString(idx, (String) param); } else if (clazz == Long.class || clazz == Long.TYPE) { preparedStatement.setLong(idx, (Long) param); } else if (clazz == Boolean.class || clazz == Boolean.TYPE) { preparedStatement.setBoolean(idx, (Boolean) param); } else if (BigInteger.class.isAssignableFrom(clazz)) { BigInteger bi = (BigInteger) param; preparedStatement.setBigDecimal(idx, new BigDecimal(bi)); } else if (Timestamp.class.isAssignableFrom(clazz)) { preparedStatement.setTimestamp(idx, (Timestamp) param); } else if (Date.class.isAssignableFrom(clazz)) { if (!java.sql.Date.class.isAssignableFrom(clazz)) { param = new java.sql.Date(((Date) param).getTime()); }/*from w ww . ja v a 2s .c o m*/ preparedStatement.setDate(idx, (java.sql.Date) param); } else if (BoundParameter.class.isAssignableFrom(clazz)) { ((BoundParameter) param).bindParam(preparedStatement, idx, context); } else { throw new SQLException("Unimplemented type mapping for " + clazz); } }
From source file:com.concursive.connect.web.modules.setup.utils.SetupUtils.java
/** * Determines if a default project has been installed * * @param db// w ww .j av a2s. c om * @return */ public static boolean isDefaultProjectInstalled(Connection db) { int count = -1; try { PreparedStatement pst = db.prepareStatement( "SELECT count(*) AS recordcount " + "FROM projects " + "WHERE system_default = ? "); pst.setBoolean(1, true); ResultSet rs = pst.executeQuery(); rs.next(); count = rs.getInt("recordcount"); rs.close(); pst.close(); } catch (Exception e) { } return count > 0; }
From source file:org.easyrec.utils.spring.store.dao.DaoUtils.java
public static void setBoolean(PreparedStatement stmt, Boolean value, int index) throws SQLException { if (value == null) { stmt.setNull(index, Types.BOOLEAN); return;/*from w w w. ja va 2s . co m*/ } stmt.setBoolean(index, value); }
From source file:com.app.dao.SearchQueryDAO.java
private static void _populateAddSearchQueryPreparedStatement(PreparedStatement preparedStatement, SearchQuery searchQuery) throws SQLException { preparedStatement.setInt(1, searchQuery.getUserId()); preparedStatement.setString(2, searchQuery.getKeywords()); preparedStatement.setString(3, searchQuery.getCategoryId()); preparedStatement.setString(4, searchQuery.getSubcategoryId()); preparedStatement.setBoolean(5, searchQuery.isSearchDescription()); preparedStatement.setBoolean(6, searchQuery.isFreeShippingOnly()); preparedStatement.setBoolean(7, searchQuery.isNewCondition()); preparedStatement.setBoolean(8, searchQuery.isUsedCondition()); preparedStatement.setBoolean(9, searchQuery.isUnspecifiedCondition()); preparedStatement.setBoolean(10, searchQuery.isAuctionListing()); preparedStatement.setBoolean(11, searchQuery.isFixedPriceListing()); preparedStatement.setDouble(12, searchQuery.getMaxPrice()); preparedStatement.setDouble(13, searchQuery.getMinPrice()); preparedStatement.setString(14, searchQuery.getGlobalId()); preparedStatement.setBoolean(15, searchQuery.isActive()); }
From source file:org.kontalk.system.Database.java
private static void setValue(PreparedStatement stat, int i, Object value) throws SQLException { if (value instanceof String) { stat.setString(i + 1, (String) value); } else if (value instanceof Integer) { stat.setInt(i + 1, (int) value); } else if (value instanceof Date) { stat.setLong(i + 1, ((Date) value).getTime()); } else if (value instanceof Boolean) { stat.setBoolean(i + 1, (boolean) value); } else if (value instanceof Enum) { stat.setInt(i + 1, ((Enum) value).ordinal()); } else if (value instanceof EnumSet) { stat.setInt(i + 1, EncodingUtils.enumSetToInt(((EnumSet) value))); } else if (value instanceof Optional) { Optional<?> o = (Optional) value; setValue(stat, i, o.orElse(null)); } else if (value == null) { stat.setNull(i + 1, Types.NULL); } else {// ww w.jav a2 s . c o m LOGGER.warning("unknown type: " + value); } }
From source file:com.dynamobi.network.DynamoNetworkUdr.java
/** * Shows all available packages we have available. *//*from www . j av a 2s . c o m*/ public static void showPackages(PreparedStatement resultInserter) throws SQLException { List<RepoInfo> repos = getRepoUrls(); for (RepoInfo inf : repos) { String repo = inf.url; if (!inf.accessible) { resultInserter.setString(1, repo); resultInserter.setBoolean(2, inf.accessible); resultInserter.executeUpdate(); continue; } JSONObject repo_data = downloadMetadata(repo); JSONArray pkgs = (JSONArray) repo_data.get("packages"); for (JSONObject obj : (List<JSONObject>) pkgs) { String jar = jarName(obj); String status = getStatus(jar); int c = 0; resultInserter.setString(++c, repo); resultInserter.setBoolean(++c, inf.accessible); resultInserter.setString(++c, obj.get("type").toString()); resultInserter.setString(++c, obj.get("publisher").toString()); resultInserter.setString(++c, obj.get("package").toString()); resultInserter.setString(++c, obj.get("version").toString()); resultInserter.setString(++c, jar); resultInserter.setString(++c, status); resultInserter.setString(++c, obj.get("depend").toString()); resultInserter.setString(++c, obj.get("rdepend").toString()); resultInserter.executeUpdate(); } } }
From source file:Main.java
public static PreparedStatement createLayersInsertForContextual(Connection conn, int layerId, String description, String path, String name, String displayPath, double minLatitude, double minLongitude, double maxLatitude, double maxLongitude, String path_orig) throws SQLException { PreparedStatement stLayersInsert = conn.prepareStatement( "INSERT INTO layers (id, name, description, type, path, displayPath, minlatitude, minlongitude, maxlatitude, maxlongitude, enabled, displayname, uid, path_orig) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"); stLayersInsert.setInt(1, layerId);/* w w w .j a v a 2 s . c o m*/ stLayersInsert.setString(2, name); stLayersInsert.setString(3, description); stLayersInsert.setString(4, CONTEXTUAL_LAYER_TYPE); stLayersInsert.setString(5, path); stLayersInsert.setString(6, displayPath); stLayersInsert.setDouble(7, minLatitude); stLayersInsert.setDouble(8, minLongitude); stLayersInsert.setDouble(9, maxLatitude); stLayersInsert.setDouble(10, maxLongitude); stLayersInsert.setBoolean(11, true); stLayersInsert.setString(12, description); stLayersInsert.setString(13, Integer.toString(layerId)); stLayersInsert.setString(14, path_orig); return stLayersInsert; }
From source file:org.mskcc.cbio.portal.dao.DaoClinicalAttribute.java
public static int addDatum(ClinicalAttribute attr) throws DaoException { Connection con = null;/*from ww w . j a va 2s. c om*/ PreparedStatement pstmt = null; ResultSet rs = null; try { con = JdbcUtil.getDbConnection(DaoClinicalAttribute.class); pstmt = con.prepareStatement( "INSERT INTO clinical_attribute(" + "`ATTR_ID`," + "`DISPLAY_NAME`," + "`DESCRIPTION`," + "`DATATYPE`," + "`PATIENT_ATTRIBUTE`," + "`PRIORITY`)" + " VALUES(?,?,?,?,?,?)"); pstmt.setString(1, attr.getAttrId()); pstmt.setString(2, attr.getDisplayName()); pstmt.setString(3, attr.getDescription()); pstmt.setString(4, attr.getDatatype()); pstmt.setBoolean(5, attr.isPatientAttribute()); pstmt.setString(6, attr.getPriority()); return pstmt.executeUpdate(); } catch (SQLException e) { throw new DaoException(e); } finally { JdbcUtil.closeAll(DaoClinicalAttribute.class, con, pstmt, rs); } }
From source file:org.hyperic.util.jdbc.DBUtil.java
/** * Fill out a PreparedStatement correctly with a boolean. * // ww w.j a v a 2 s . c o m * @param bool - the boolean you want * @param conn - a connection * @return booleanStr - the appropriate boolean string for the db you're * using */ public static void setBooleanValue(boolean bool, Connection conn, PreparedStatement ps, int idx) throws SQLException { int type = getDBType(conn); switch (type) { case DATABASE_ORACLE_8: case DATABASE_ORACLE_9: case DATABASE_ORACLE_10: case DATABASE_ORACLE_11: case DATABASE_MYSQL5: ps.setInt(idx, (bool) ? 1 : 0); return; default: ps.setBoolean(idx, bool); return; } }
From source file:org.mskcc.cbio.portal.dao.DaoClinicalAttributeMeta.java
public static int addDatum(ClinicalAttribute attr) throws DaoException { Connection con = null;//from ww w.ja va2 s . c om PreparedStatement pstmt = null; ResultSet rs = null; try { con = JdbcUtil.getDbConnection(DaoClinicalAttributeMeta.class); pstmt = con.prepareStatement("INSERT INTO clinical_attribute_meta(" + "`ATTR_ID`," + "`DISPLAY_NAME`," + "`DESCRIPTION`," + "`DATATYPE`," + "`PATIENT_ATTRIBUTE`," + "`PRIORITY`," + "`CANCER_STUDY_ID`)" + " VALUES(?,?,?,?,?,?,?)"); pstmt.setString(1, attr.getAttrId()); pstmt.setString(2, attr.getDisplayName()); pstmt.setString(3, attr.getDescription()); pstmt.setString(4, attr.getDatatype()); pstmt.setBoolean(5, attr.isPatientAttribute()); pstmt.setString(6, attr.getPriority()); pstmt.setInt(7, attr.getCancerStudyId()); return pstmt.executeUpdate(); } catch (SQLException e) { throw new DaoException(e); } finally { JdbcUtil.closeAll(DaoClinicalAttributeMeta.class, con, pstmt, rs); } }