List of usage examples for java.sql PreparedStatement setString
void setString(int parameterIndex, String x) throws SQLException;
String
value. From source file:com.att.pirates.controller.GlobalDataController.java
public static boolean isATTEmployeeITUPRoleEmpty(String UUID) { ResultSet rs = null;/*ww w. j av a 2s. c o m*/ Connection conn = null; PreparedStatement preparedStatement = null; boolean rc = false; try { conn = DBUtility.getDBConnection(); // SQL query command String SQL = " select * from ATTEmployeeArtifacts where uuid = ? "; preparedStatement = conn.prepareStatement(SQL); preparedStatement.setString(1, UUID); rs = preparedStatement.executeQuery(); if (rs.next()) { rc = true; } } catch (SQLException e) { logger.error(e.getMessage()); } catch (Exception e) { logger.error(e.getMessage()); } finally { try { if (rs != null) rs.close(); } catch (Exception e) { } ; try { if (preparedStatement != null) preparedStatement.close(); } catch (Exception e) { } ; try { if (conn != null) conn.close(); } catch (Exception e) { } ; } return rc; }
From source file:com.wso2telco.dep.reportingservice.dao.OperatorDAO.java
/** * Gets the applications by operator.//from w w w . ja va 2s . co m * * @param operatorName the operator name * @return the applications by operator * @throws APIMgtUsageQueryServiceClientException the API mgt usage query service client exception * @throws SQLException the SQL exception */ public static List<Integer> getApplicationsByOperator(String operatorName) throws APIMgtUsageQueryServiceClientException, SQLException { Connection conn = null; PreparedStatement ps = null; ResultSet results = null; String sql = "SELECT opcoApp.applicationid FROM " + ReportingTable.OPERATORAPPS + " opcoApp INNER JOIN " + ReportingTable.OPERATORS + " opco ON opcoApp.operatorid = opco.id WHERE opco.operatorname =? AND opcoApp.isactive = 1"; List<Integer> applicationIds = new ArrayList<Integer>(); try { conn = DbUtils.getDbConnection(DataSourceNames.WSO2TELCO_DEP_DB); ps = conn.prepareStatement(sql); ps.setString(1, operatorName); log.debug("getApplicationsByOperator"); results = ps.executeQuery(); while (results.next()) { int temp = results.getInt("applicationid"); applicationIds.add(temp); } } catch (Exception e) { log.error("Error occured while getting application ids from the database" + e); } finally { DbUtils.closeAllConnections(ps, conn, results); } return applicationIds; }
From source file:com.keybox.manage.db.PublicKeyDB.java
/** * updates existing public key//w w w. j a v a 2 s. c o m * * @param publicKey key object */ public static void updatePublicKey(PublicKey publicKey) { Connection con = null; try { con = DBUtils.getConn(); PreparedStatement stmt = con.prepareStatement( "update public_keys set key_nm=?, type=?, fingerprint=?, public_key=?, profile_id=? where id=? and user_id=? and enabled=true"); stmt.setString(1, publicKey.getKeyNm()); stmt.setString(2, SSHUtil.getKeyType(publicKey.getPublicKey())); stmt.setString(3, SSHUtil.getFingerprint(publicKey.getPublicKey())); stmt.setString(4, publicKey.getPublicKey().trim()); if (publicKey.getProfile() == null || publicKey.getProfile().getId() == null) { stmt.setNull(5, Types.NULL); } else { stmt.setLong(5, publicKey.getProfile().getId()); } stmt.setLong(6, publicKey.getId()); stmt.setLong(7, publicKey.getUserId()); stmt.execute(); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } DBUtils.closeConn(con); }
From source file:com.akman.excel.controller.CURDInvoice.java
public static void Save(Invoice inv) { Connection conn = Javaconnect.ConnecrDb(); PreparedStatement pst = null; ResultSet rs = null;//from w w w . ja va 2 s . com try { String sql = "INSERT INTO Invoice " + "(InvoiceNo,OrderNo, Date,TinNo,ReferenceNo,CountryOfOrigin,MOP,PaymentTerms,TrackingNo,S_Name," + " S_Address1, S_Address2, S_Address3, S_City, S_State, S_PinCode, S_PhoneNo, S_Country, B_Name, B_Address1, B_Address2, B_Address3, B_City," + " B_State, B_PinCode, B_PhoneNo, B_Country, PakegeType, Quantity, Rate, Description, CatagoryItem, Category)" + " VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; pst = conn.prepareStatement(sql); pst.setString(1, inv.getInvoiceNo()); pst.setString(2, inv.getOrderNo()); pst.setString(3, inv.getDate()); pst.setString(4, inv.getTinNo()); pst.setString(5, inv.getReferenceNo()); pst.setString(6, inv.getCountryOfOrigin()); pst.setString(7, inv.getMOP()); pst.setString(8, inv.getPaymentTerms()); pst.setString(9, inv.getTrackingNo()); pst.setString(10, inv.getSender().getName()); pst.setString(11, inv.getSender().getAddress1()); pst.setString(12, inv.getSender().getAddress2()); pst.setString(13, inv.getSender().getAddress3()); pst.setString(14, inv.getSender().getCity()); pst.setString(15, inv.getSender().getState()); pst.setString(16, inv.getSender().getPinCode()); pst.setString(17, inv.getSender().getPhoneNo()); pst.setString(18, inv.getSender().getCountry()); pst.setString(19, inv.getBuyer().getName()); pst.setString(20, inv.getBuyer().getAddress1()); pst.setString(21, inv.getBuyer().getAddress2()); pst.setString(22, inv.getBuyer().getAddress3()); pst.setString(23, inv.getBuyer().getCity()); pst.setString(24, inv.getBuyer().getState()); pst.setString(25, inv.getBuyer().getPinCode()); pst.setString(26, inv.getBuyer().getPhoneNo()); pst.setString(27, inv.getBuyer().getCountry()); pst.setString(28, inv.getOrder().getPakegeType()); pst.setDouble(29, inv.getOrder().getQuantity()); pst.setDouble(30, inv.getOrder().getRate()); pst.setString(31, inv.getOrder().getDescription()); pst.setString(32, inv.getCatagoryItem()); pst.setString(33, inv.getCategory()); pst.execute(); } catch (SQLException ex) { Logger.getLogger(CURDInvoice.class.getName()).log(Level.SEVERE, null, ex); } finally { DbUtils.closeQuietly(rs); DbUtils.closeQuietly(pst); DbUtils.closeQuietly(conn); } }
From source file:com.concursive.connect.web.modules.profile.utils.ProjectUtils.java
public static synchronized String updateUniqueId(Connection db, int projectId, String title) throws SQLException { if (projectId == -1) { throw new SQLException("ID was not specified"); }//from www . j av a 2 s. c o m if (title == null) { throw new SQLException("Title was not specified"); } // reserve a unique text id for the project String uniqueId = ProjectUtils.generateUniqueId(title, projectId, db); PreparedStatement pst = db .prepareStatement("UPDATE projects " + "SET projecttextid = ? " + "WHERE project_id = ?"); pst.setString(1, uniqueId); pst.setInt(2, projectId); pst.execute(); pst.close(); CacheUtils.invalidateValue(Constants.SYSTEM_PROJECT_CACHE, projectId); CacheUtils.invalidateValue(Constants.SYSTEM_PROJECT_UNIQUE_ID_CACHE, uniqueId); return uniqueId; }
From source file:module.entities.NameFinder.DB.java
/** * Starts the activity log/*from w w w .jav a 2 s. c o m*/ * * @param startTime - The start time of the crawling procedure * @return - The activity's log id * @throws java.sql.SQLException */ public static int LogRegexFinder(long startTime) throws SQLException { String insertLogSql = "INSERT INTO log.activities (module_id, start_date, end_date, status_id, message) VALUES (?,?,?,?,?)"; PreparedStatement prepLogCrawlStatement = connection.prepareStatement(insertLogSql, Statement.RETURN_GENERATED_KEYS); prepLogCrawlStatement.setInt(1, 4); prepLogCrawlStatement.setTimestamp(2, new java.sql.Timestamp(startTime)); prepLogCrawlStatement.setTimestamp(3, null); prepLogCrawlStatement.setInt(4, 1); prepLogCrawlStatement.setString(5, null); prepLogCrawlStatement.executeUpdate(); ResultSet rsq = prepLogCrawlStatement.getGeneratedKeys(); int crawlerId = 0; if (rsq.next()) { crawlerId = rsq.getInt(1); } prepLogCrawlStatement.close(); return crawlerId; }
From source file:module.entities.NameFinder.DB.java
public static void insertJsonResponse(int curConsId, TreeMap<Integer, String> input) throws SQLException { try {/*from w w w .j a v a2s .c o m*/ String insertSQL = "INSERT INTO enhancedentities " + "(consultation_id,article_id,json_text) VALUES" + "(?,?,?);"; PreparedStatement prepStatement = connection.prepareStatement(insertSQL); // connection.setAutoCommit(false); for (int curArticle : input.keySet()) { String json_text = input.get(curArticle); prepStatement.setInt(1, curConsId); prepStatement.setInt(2, curArticle); prepStatement.setString(3, json_text); // prepStatement.executeUpdate(); prepStatement.addBatch(); } prepStatement.executeBatch(); // connection.commit(); prepStatement.close(); // for (int i = 0; i<x.length; i++){ // System.out.println(x[i]); // } } catch (BatchUpdateException ex) { ex.printStackTrace(); // System.out.println(ex.getNextException()); } }
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 ava 2s. c o m*/ 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.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());/*w ww . ja va2 s.co 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; } }
From source file:com.concursive.connect.web.modules.register.beans.RegisterBean.java
/** * Description of the Method//from www .j a v a2 s . c om * * @param db Description of the Parameter * @param partialUserRecord Description of the Parameter * @return Description of the Return Value * @throws SQLException Description of the Exception */ private static void updateRegisteredStatus(Connection db, User partialUserRecord) throws SQLException { // NOTE: Assume the user object isn't complete, so can't load it, etc. { // Approve the user PreparedStatement pst = db .prepareStatement("UPDATE users " + "SET first_name = ?, last_name = ?, password = ?, " + "company = ?, registered = ?, enabled = ?, terms = ? " + "WHERE user_id = ? "); int i = 0; pst.setString(++i, partialUserRecord.getFirstName()); pst.setString(++i, partialUserRecord.getLastName()); pst.setString(++i, partialUserRecord.getPassword()); pst.setString(++i, partialUserRecord.getCompany()); pst.setBoolean(++i, true); pst.setBoolean(++i, true); pst.setBoolean(++i, partialUserRecord.getTerms()); pst.setInt(++i, partialUserRecord.getId()); pst.executeUpdate(); pst.close(); CacheUtils.invalidateValue(Constants.SYSTEM_USER_CACHE, partialUserRecord.getId()); } { // Approve the user's profile and update their location User user = UserUtils.loadUser(partialUserRecord.getId()); if (user == null) { LOG.warn("updateRegisteredStatus - USER RECORD IS NULL"); } else { Project profile = ProjectUtils.loadProject(user.getProfileProjectId()); if (profile == null) { LOG.warn("updateRegisteredStatus - PROFILE RECORD IS NULL"); } else { profile.setApproved(true); profile.setCity(partialUserRecord.getCity()); profile.setState(partialUserRecord.getState()); profile.setCountry(partialUserRecord.getCountry()); profile.setPostalCode(partialUserRecord.getPostalCode()); profile.update(db); } } } }