List of usage examples for java.sql PreparedStatement setInt
void setInt(int parameterIndex, int x) throws SQLException;
int
value. From source file:com.wso2telco.util.DbUtil.java
public static void updatePin(int pin, String sessionId) throws SQLException, AuthenticatorException { Connection connection = null; PreparedStatement ps = null; String sql = "update multiplepasswords set pin=? where ussdsessionid = ?;"; connection = getConnectDBConnection(); ps = connection.prepareStatement(sql); ps.setInt(1, pin); ps.setString(2, sessionId);//from w w w. j a v a 2 s . c om ps.execute(); if (connection != null) { connection.close(); } }
From source file:com.wso2telco.util.DbUtil.java
public static void updateMultiplePasswordNoOfAttempts(String username, int attempts) throws SQLException, AuthenticatorException { Connection connection = null; PreparedStatement ps = null; String sql = "update `multiplepasswords` set attempts=? where username=?;"; connection = getConnectDBConnection(); ps = connection.prepareStatement(sql); ps.setInt(1, attempts); ps.setString(2, username);/*from ww w. j a v a2 s. com*/ ps.execute(); if (connection != null) { connection.close(); } }
From source file:fll.Team.java
/** * Builds a team object from its database info given the team number. * /*from ww w .j av a 2 s .com*/ * @param connection Database connection. * @param teamNumber Number of the team for which to build an object. * @return The new Team object or null if the team was not found in the * database. * @throws SQLException on a database access error. */ public static Team getTeamFromDatabase(final Connection connection, final int teamNumber) throws SQLException { // First, handle known non-database team numbers... if (teamNumber == NULL_TEAM_NUMBER) { return NULL; } if (teamNumber == TIE_TEAM_NUMBER) { return TIE; } if (teamNumber == BYE_TEAM_NUMBER) { return BYE; } PreparedStatement stmt = null; ResultSet rs = null; try { stmt = connection.prepareStatement( "SELECT Division, Organization, TeamName FROM Teams" + " WHERE TeamNumber = ?"); stmt.setInt(1, teamNumber); rs = stmt.executeQuery(); if (rs.next()) { final String division = rs.getString(1); final String org = rs.getString(2); final String name = rs.getString(3); final Team x = new Team(teamNumber, org, name, division); return x; } else { return null; } } finally { SQLFunctions.close(rs); SQLFunctions.close(stmt); } }
From source file:au.org.ala.sds.GeneraliseOccurrenceLocations.java
private static void run(String startAt) throws SQLException, SearchResultException { Connection conn = occurrenceDataSource.getConnection(); PreparedStatement pst = conn.prepareStatement( "SELECT id, scientific_name, latitude, longitude, generalised_metres, raw_latitude, raw_longitude FROM raw_occurrence_record LIMIT ?,?"); int offset = startAt == null ? 0 : Integer.parseInt(startAt); int stride = 10000; int recCount = 0; pst.setInt(2, stride); ResultSet rs;/*from www. ja v a 2s. c o m*/ for (pst.setInt(1, offset); true; offset += stride, pst.setInt(1, offset)) { rs = pst.executeQuery(); if (!rs.isBeforeFirst()) { break; } while (rs.next()) { recCount++; String rawScientificName = (rs.getString("scientific_name")); int id = rs.getInt("id"); String latitude = rs.getString("latitude"); String longitude = rs.getString("longitude"); String generalised_metres = rs.getString("generalised_metres"); String raw_latitude = rs.getString("raw_latitude"); String raw_longitude = rs.getString("raw_longitude"); if (StringUtils.isEmpty(rawScientificName)) continue; if (StringUtils.isEmpty(latitude) || StringUtils.isEmpty(longitude)) continue; // See if it's sensitive SensitiveTaxon ss = sensitiveSpeciesFinder.findSensitiveSpecies(rawScientificName); if (ss != null) { Map<String, String> facts = new HashMap<String, String>(); facts.put(FactCollection.DECIMAL_LATITUDE_KEY, latitude); facts.put(FactCollection.DECIMAL_LONGITUDE_KEY, longitude); ValidationService service = ServiceFactory.createValidationService(ss); ValidationOutcome outcome = service.validate(facts); Map<String, Object> result = outcome.getResult(); String speciesName = ss.getTaxonName(); if (StringUtils.isNotEmpty(ss.getCommonName())) { speciesName += " [" + ss.getCommonName() + "]"; } if (!result.get("decimalLatitude").equals(facts.get("decimalLatitude")) || !result.get("decimalLongitude").equals(facts.get("decimalLongitude"))) { if (StringUtils.isEmpty(generalised_metres)) { logger.info("Generalising location for " + id + " '" + rawScientificName + "' using Name='" + speciesName + "', Lat=" + result.get("decimalLatitude") + ", Long=" + result.get("decimalLongitude")); //rawOccurrenceDao.updateLocation(id, result.get("decimalLatitude"), result.get("decimalLongitude"), result.getGeneralisationInMetres(), latitude, longitude); } else { if (generalised_metres != result.get("generalisationInMetres")) { logger.info("Re-generalising location for " + id + " '" + rawScientificName + "' using Name='" + speciesName + "', Lat=" + result.get("decimalLatitude") + ", Long=" + result.get("decimalLongitude")); //rawOccurrenceDao.updateLocation(id, result.get("decimalLatitude"), result.get("decimalLongitude"), result.getGeneralisationInMetres()); } } } else { logger.info("Not generalising location for " + id + " '" + rawScientificName + "' using Name='" + speciesName + "', Lat=" + result.get("decimalLatitude") + ", Long=" + result.get("decimalLongitude") + " - " + result.get("dataGeneralizations")); } } else { // See if was sensitive but not now if (StringUtils.isNotEmpty(generalised_metres)) { logger.info("De-generalising location for " + id + " '" + rawScientificName + "', Lat=" + raw_latitude + ", Long=" + raw_longitude); //rawOccurrenceDao.updateLocation(id, raw_latitude, raw_longitude, null, null, null); } } } rs.close(); logger.info("Processed " + recCount + " occurrence records."); } rs.close(); pst.close(); conn.close(); }
From source file:fll.db.NonNumericNominees.java
/** * Get all nominees in the specified category. * /*from w w w .j a v a 2s. c o m*/ * @throws SQLException */ public static Set<Integer> getNominees(final Connection connection, final int tournamentId, final String category) throws SQLException { final Set<Integer> result = new HashSet<>(); PreparedStatement get = null; ResultSet rs = null; try { get = connection.prepareStatement( "SELECT DISTINCT team_number FROM non_numeric_nominees" + " WHERE tournament = ?" // + " AND category = ?"); get.setInt(1, tournamentId); get.setString(2, category); rs = get.executeQuery(); while (rs.next()) { final int team = rs.getInt(1); result.add(team); } } finally { SQLFunctions.close(rs); SQLFunctions.close(get); } return result; }
From source file:com.l2jfree.gameserver.instancemanager.CursedWeaponsManager.java
public static void removeFromDb(int itemId) { Connection con = null;/*from w ww .j a v a 2 s . c om*/ try { con = L2DatabaseFactory.getInstance().getConnection(con); // Delete datas PreparedStatement statement = con.prepareStatement("DELETE FROM cursed_weapons WHERE itemId = ?"); statement.setInt(1, itemId); statement.executeUpdate(); statement.close(); } catch (SQLException e) { _log.fatal("CursedWeaponsManager: Failed to remove data: ", e); } finally { L2DatabaseFactory.close(con); } }
From source file:com.trackplus.ddl.DataWriter.java
private static void insertBlobData(Connection con, String line) throws DDLException { String sql = "INSERT INTO TBLOB(OBJECTID, BLOBVALUE, TPUUID) VALUES(?,?,?)"; StringTokenizer st = new StringTokenizer(line, ","); Integer objectID = Integer.valueOf(st.nextToken()); String base64Str = st.nextToken(); byte[] bytes = Base64.decodeBase64(base64Str); String tpuid = null;// w ww . j av a 2 s. co m if (st.hasMoreTokens()) { tpuid = st.nextToken(); } try { PreparedStatement preparedStatement = con.prepareStatement(sql); preparedStatement.setInt(1, objectID); preparedStatement.setBinaryStream(2, new ByteArrayInputStream(bytes), bytes.length); preparedStatement.setString(3, tpuid); preparedStatement.executeUpdate(); } catch (SQLException e) { throw new DDLException(e.getMessage(), e); } }
From source file:com.wso2telco.util.DbUtil.java
public static void insertPinAttempt(String msisdn, int attempts, String sessionId) throws SQLException, AuthenticatorException { Connection connection = null; PreparedStatement ps = null; String sql = "insert into multiplepasswords(username, attempts, ussdsessionid) values (?,?,?);"; connection = getConnectDBConnection(); ps = connection.prepareStatement(sql); ps.setString(1, msisdn);/*from w ww . java 2 s . c o m*/ ps.setInt(2, attempts); ps.setString(3, sessionId); ps.execute(); if (connection != null) { connection.close(); } }
From source file:DeliverWork.java
private static String saveIntoWeed(RemoteFile remoteFile, String projectId) throws SQLException, UnsupportedEncodingException { String url = "http://59.215.226.174/WebDiskServerDemo/doc?doc_id=" + URLEncoder.encode(remoteFile.getFileId(), "utf-8"); CloseableHttpClient httpClient = null; CloseableHttpResponse response = null; String res = ""; try {/*from www . j av a 2 s .c o m*/ httpClient = HttpClients.createSystem(); // http(get?) HttpGet httpget = new HttpGet(url); response = httpClient.execute(httpget); HttpEntity result = response.getEntity(); String fileName = remoteFile.getFileName(); FileHandleStatus fileHandleStatus = getFileTemplate().saveFileByStream(fileName, new ByteArrayInputStream(EntityUtils.toByteArray(result))); System.out.println(fileHandleStatus); File file = new File(); if (result != null && result.getContentType() != null && result.getContentType().getValue() != null) { file.setContentType(result.getContentType().getValue()); } else { file.setContentType("application/error"); } file.setDataId(Integer.parseInt(projectId)); file.setName(fileName); if (fileName.contains(".bmp") || fileName.contains(".jpg") || fileName.contains(".jpeg") || fileName.contains(".png") || fileName.contains(".gif")) { file.setType(1); } else if (fileName.contains(".doc") || fileName.contains(".docx")) { file.setType(2); } else if (fileName.contains(".xlsx") || fileName.contains("xls")) { file.setType(3); } else if (fileName.contains(".pdf")) { file.setType(4); } else { file.setType(5); } String accessUrl = "/" + fileHandleStatus.getFileId().replaceAll(",", "/").concat("/").concat(fileName); file.setUrl(accessUrl); file.setSize(fileHandleStatus.getSize()); file.setPostTime(new java.util.Date()); file.setStatus(0); file.setEnumValue(findFileType(remoteFile.getFileType())); file.setResources(1); // JdbcFactory jdbcFactoryChanye=new JdbcFactory("jdbc:mysql://127.0.0.1:3306/fp_guimin?useUnicode=true&characterEncoding=UTF-8","root","111111","com.mysql.jdbc.Driver"); // Connection connection = jdbcFactoryChanye.getConnection(); DatabaseMetaData dmd = connection.getMetaData(); PreparedStatement ps = connection.prepareStatement(insertFile, new String[] { "ID" }); ps.setString(1, sdf.format(file.getPostTime())); ps.setInt(2, file.getType()); ps.setString(3, file.getEnumValue()); ps.setInt(4, file.getDataId()); ps.setString(5, file.getUrl()); ps.setString(6, file.getName()); ps.setString(7, file.getContentType()); ps.setLong(8, file.getSize()); ps.setInt(9, file.getStatus()); ps.setInt(10, file.getResources()); ps.executeUpdate(); if (dmd.supportsGetGeneratedKeys()) { ResultSet rs = ps.getGeneratedKeys(); while (rs.next()) { System.out.println(rs.getLong(1)); } } ps.close(); res = "success"; } catch (ClientProtocolException e) { e.printStackTrace(); res = e.getMessage(); } catch (IOException e) { e.printStackTrace(); res = e.getMessage(); } catch (Exception ex) { ex.printStackTrace(); } finally { if (httpClient != null) { try { httpClient.close(); } catch (IOException e) { e.printStackTrace(); } } if (response != null) { try { response.close(); } catch (IOException e) { e.printStackTrace(); } } } return res; }
From source file:com.concursive.connect.web.modules.communications.utils.EmailUpdatesUtils.java
public static void manageQueue(Connection db, TeamMember teamMember) throws SQLException { //Determine if the member is part of any other projects and has a matching email updates preference PreparedStatement pst = db.prepareStatement("SELECT count(*) AS record_count " + "FROM project_team pt " + "WHERE pt.user_id = ? " + "AND pt.email_updates_schedule = ? "); int i = 0;//from w w w.jav a 2 s . com pst.setInt(++i, teamMember.getUserId()); pst.setInt(++i, teamMember.getEmailUpdatesSchedule()); ResultSet rs = pst.executeQuery(); int records = 0; if (rs.next()) { records = rs.getInt("record_count"); } rs.close(); pst.close(); if (records == 0) { //Delete the queue since it is no longer needed. String field = ""; int emailUpdatesSchedule = teamMember.getEmailUpdatesSchedule(); if (emailUpdatesSchedule > 0) { if (emailUpdatesSchedule == TeamMember.EMAIL_OFTEN) { field = "schedule_often"; } else if (emailUpdatesSchedule == TeamMember.EMAIL_DAILY) { field = "schedule_daily"; } else if (emailUpdatesSchedule == TeamMember.EMAIL_WEEKLY) { field = "schedule_weekly"; } else if (emailUpdatesSchedule == TeamMember.EMAIL_MONTHLY) { field = "schedule_monthly"; } i = 0; pst = db.prepareStatement( "DELETE FROM email_updates_queue " + "WHERE enteredby = ? AND " + field + " = ? "); pst.setInt(++i, teamMember.getUserId()); pst.setBoolean(++i, true); pst.executeUpdate(); pst.close(); } } }