List of usage examples for java.sql PreparedStatement setInt
void setInt(int parameterIndex, int x) throws SQLException;
int
value. From source file:dsd.dao.DAOProvider.java
/** * calls the correct method for setting the command parameter depending on * parameter type//from www. j ava 2s . c o m * * @param command * @param object * @param parameterIndex * @throws SQLException */ private static void SetParameter(PreparedStatement command, Object object, int parameterIndex) throws SQLException { if (object instanceof Timestamp) { command.setTimestamp(parameterIndex, (Timestamp) object); } else if (object instanceof String) { command.setString(parameterIndex, (String) object); } else if (object instanceof Long) { command.setLong(parameterIndex, (Long) object); } else if (object instanceof Integer) { command.setInt(parameterIndex, (Integer) object); } else if (object instanceof Boolean) { command.setBoolean(parameterIndex, (Boolean) object); } else if (object instanceof Float) { command.setFloat(parameterIndex, (Float) object); } else { throw new IllegalArgumentException( "type needs to be inserted in Set parameter method of DAOProvider class"); } }
From source file:com.concursive.connect.web.modules.login.utils.UserUtils.java
public static boolean detachProfile(Connection db, int projectId) throws SQLException { PreparedStatement pst = db.prepareStatement( "UPDATE users " + "SET profile_project_id = ? " + "WHERE profile_project_id = ? "); int i = 0;/*from w w w. j a v a 2s. co m*/ DatabaseUtils.setInt(pst, ++i, -1); pst.setInt(++i, projectId); int count = pst.executeUpdate(); pst.close(); return count == 1; }
From source file:com.wso2telco.dep.reportingservice.dao.OperatorDAO.java
/** * Gets the operator names by application. * * @param applicationId the application id * @return the operator names by application * @throws APIMgtUsageQueryServiceClientException the API mgt usage query service client exception * @throws SQLException the SQL exception *///from ww w . j a v a 2 s . c o m public static List<String> getOperatorNamesByApplication(int applicationId) throws APIMgtUsageQueryServiceClientException, SQLException { Connection conn = null; PreparedStatement ps = null; ResultSet results = null; String sql = "SELECT opco.operatorname FROM " + ReportingTable.OPERATORAPPS + " opcoApp INNER JOIN " + ReportingTable.OPERATORS + " opco ON opcoApp.operatorid = opco.id WHERE opcoApp.applicationid =? AND opcoApp.isactive = 1"; List<String> operatorNames = new ArrayList<String>(); try { conn = DbUtils.getDbConnection(DataSourceNames.WSO2TELCO_DEP_DB); ps = conn.prepareStatement(sql); ps.setInt(1, applicationId); log.debug("getOperatorNamesByApplication"); results = ps.executeQuery(); while (results.next()) { String temp = results.getString("operatorname"); operatorNames.add(temp); } } catch (Exception e) { log.error("Error occured while getting operator names from the database" + e); } finally { DbUtils.closeAllConnections(ps, conn, results); } return operatorNames; }
From source file:at.becast.youploader.database.SQLite.java
public static Boolean updateUploadData(Video data, VideoMetadata metadata, int id) throws SQLException, IOException { PreparedStatement prest = null; ObjectMapper mapper = new ObjectMapper(); String sql = "UPDATE `uploads` SET `data`=?,`metadata`=? WHERE `id`=?"; prest = c.prepareStatement(sql);/* ww w . j a va2 s. com*/ prest.setString(1, mapper.writeValueAsString(data)); prest.setString(2, mapper.writeValueAsString(metadata)); prest.setInt(3, id); boolean res = prest.execute(); prest.close(); return res; }
From source file:com.act.lcms.db.model.CuratedChemical.java
protected static void bindInsertOrUpdateParameters(PreparedStatement stmt, String name, String inchi, Double mPlusHPlusMass, Integer expectedCollisionVoltage, String referenceUrl) throws SQLException { stmt.setString(DB_FIELD.NAME.getInsertUpdateOffset(), name); stmt.setString(DB_FIELD.INCHI.getInsertUpdateOffset(), inchi); stmt.setDouble(DB_FIELD.MASS.getInsertUpdateOffset(), mPlusHPlusMass); if (expectedCollisionVoltage != null) { stmt.setInt(DB_FIELD.EXPECTED_COLLISION_VOLTAGE.getInsertUpdateOffset(), expectedCollisionVoltage); } else {//from w w w . j ava2 s.c o m stmt.setNull(DB_FIELD.EXPECTED_COLLISION_VOLTAGE.getInsertUpdateOffset(), Types.INTEGER); } stmt.setString(DB_FIELD.REFERENCE_URL.getInsertUpdateOffset(), referenceUrl); }
From source file:at.becast.youploader.database.SQLite.java
public static Boolean prepareUpload(int id, String Url, String yt_id) { PreparedStatement prest = null; String sql = "UPDATE `uploads` SET `status`=?,`url`=?,`yt_id`=? WHERE `id`=?"; try {//from w w w. j av a 2s .com prest = c.prepareStatement(sql); prest.setString(1, UploadManager.Status.PREPARED.toString()); prest.setString(2, Url); prest.setString(3, yt_id); prest.setInt(4, id); boolean res = prest.execute(); prest.close(); return res; } catch (SQLException e) { LOG.error("Error preparing upload", e); return false; } }
From source file:com.wso2telco.dep.reportingservice.dao.OperatorDAO.java
/** * Gets the approved operators by application. * * @param applicationId the application id * @param operator the operator// ww w. j av a 2 s .c o m * @return the approved operators by application */ public static String getApprovedOperatorsByApplication(int applicationId, String operator) { Connection conn = null; PreparedStatement ps = null; ResultSet rs = null; String sql = "SELECT opco.operatorname FROM " + ReportingTable.OPERATORAPPS + " opcoApp INNER JOIN " + ReportingTable.OPERATORS + " opco ON opcoApp.operatorid = opco.id WHERE opcoApp.isactive = 1 AND opcoApp.applicationid = ? AND opco.operatorname like ?"; String approvedOperators = ""; try { conn = DbUtils.getDbConnection(DataSourceNames.WSO2TELCO_DEP_DB); ps = conn.prepareStatement(sql); ps.setInt(1, applicationId); if (operator.equals("__ALL__")) { ps.setString(2, "%"); } else { ps.setString(2, operator); } log.debug("getApprovedOperatorsByApplication"); rs = ps.executeQuery(); while (rs.next()) { String temp = rs.getString("operatorname"); approvedOperators = approvedOperators + ", " + temp; } } catch (Exception e) { log.error("Error occured while getting approved operators of application from the database" + e); } finally { DbUtils.closeAllConnections(ps, conn, rs); } if (approvedOperators == "") { approvedOperators = "NONE"; } else { approvedOperators = approvedOperators.replaceFirst(",", ""); } return approvedOperators; }
From source file:com.wso2telco.dep.subscriptionvalidator.util.ValidatorDBUtils.java
/** * Gets the validator class for subscription. * * @param applicationId the application id * @param apiId the api id/*from ww w . jav a 2 s. c o m*/ * @return the validator class for subscription * @throws ValidatorException the validator exception */ public static String getValidatorClassForSubscription(int applicationId, int apiId) throws ValidatorException { Connection conn = null; PreparedStatement ps = null; ResultSet results = null; String sql = "SELECT class FROM validator, subscription_validator " + "WHERE subscription_validator.application_id=? AND subscription_validator.api_id=? AND " + "validator.id=subscription_validator.validator_id"; String validatorClass = null; try { conn = DbUtils.getDbConnection(DataSourceNames.WSO2TELCO_DEP_DB); ps = conn.prepareStatement(sql); log.debug("getValidatorClassForSubscription for applicationId---> " + applicationId + " apiId--> " + apiId); ps.setInt(1, applicationId); ps.setInt(2, apiId); results = ps.executeQuery(); while (results.next()) { validatorClass = results.getString("class"); } } catch (Exception e) { handleException("Error occured while getting Validator Class for App: " + applicationId + " API: " + apiId + " from the database", e); } finally { closeAllConnections(ps, conn, results); } return validatorClass; }
From source file:lineage2.gameserver.model.pledge.SubUnit.java
/** * Method removeMemberInDatabase./*w ww . ja va2 s . c om*/ * @param member UnitMember */ private static void removeMemberInDatabase(UnitMember member) { Connection con = null; PreparedStatement statement = null; try { con = DatabaseFactory.getInstance().getConnection(); statement = con.prepareStatement( "UPDATE characters SET clanid=0, pledge_type=?, pledge_rank=0, lvl_joined_academy=0, apprentice=0, title='', leaveclan=? WHERE obj_Id=?"); statement.setInt(1, Clan.SUBUNIT_NONE); statement.setLong(2, System.currentTimeMillis() / 1000); statement.setInt(3, member.getObjectId()); statement.execute(); } catch (Exception e) { _log.warn("Exception: " + e, e); } finally { DbUtils.closeQuietly(con, statement); } }
From source file:at.becast.youploader.database.SQLite.java
public static int addUpload(File file, Video data, VideoMetadata metadata, Date startAt) throws SQLException, IOException { PreparedStatement prest = null; ObjectMapper mapper = new ObjectMapper(); String sql = "INSERT INTO `uploads` (`account`, `file`, `lenght`, `data`,`enddir`, `metadata`, `status`,`starttime`) " + "VALUES (?,?,?,?,?,?,?,?)"; prest = c.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); prest.setInt(1, metadata.getAccount()); prest.setString(2, file.getAbsolutePath()); prest.setLong(3, file.length());/*from w ww.j a v a 2s. c o m*/ prest.setString(4, mapper.writeValueAsString(data)); prest.setString(5, metadata.getEndDirectory()); prest.setString(6, mapper.writeValueAsString(metadata)); prest.setString(7, UploadManager.Status.NOT_STARTED.toString()); if (startAt == null) { prest.setString(8, ""); } else { prest.setDate(8, new java.sql.Date(startAt.getTime())); } prest.execute(); ResultSet rs = prest.getGeneratedKeys(); prest.close(); if (rs.next()) { int id = rs.getInt(1); rs.close(); return id; } else { return -1; } }