List of usage examples for java.sql PreparedStatement setString
void setString(int parameterIndex, String x) throws SQLException;
String
value. From source file:com.recomdata.grails.rositaui.etl.dao.ValidationErrorBatchPreparedStatementSetter.java
@Override public void setValues(PreparedStatement ps, int i) throws SQLException { ValidationError v = items.get(i);//from w w w. j a v a 2 s . c o m ps.setString(1, v.getType()); ps.setLong(2, v.getLineNumber()); ps.setString(3, v.getMessage()); ps.setTimestamp(4, new Timestamp(v.getDate().getTime())); ps.setString(5, v.getSchema()); ps.setString(6, v.getLocation()); ps.setString(7, v.getSourceType()); ps.setString(8, v.getFilename()); }
From source file:com.wso2telco.dbUtil.DataBaseConnectUtils.java
/** * Add user details in Back Channeling Scenario * * @param backChannelUserDetails BackChannelRequestDetails */// w w w. j a v a 2s . c o m public static void addBackChannelRequestDetails(BackChannelRequestDetails backChannelUserDetails) throws ConfigurationException, CommonAuthenticatorException { Connection connection = null; PreparedStatement preparedStatement = null; String addUserDetailsQuery = "insert into backchannel_request_details(correlation_id,msisdn,notification_bearer_token," + "notification_url,request_initiated_time,client_id,redirect_url) values(?," + "?,?,?,NOW(),?,?);"; try { connection = getConnectDBConnection(); if (log.isDebugEnabled()) { log.debug("Executing the query " + addUserDetailsQuery); } preparedStatement = connection.prepareStatement(addUserDetailsQuery); preparedStatement.setString(1, backChannelUserDetails.getCorrelationId()); preparedStatement.setString(2, backChannelUserDetails.getMsisdn()); preparedStatement.setString(3, backChannelUserDetails.getNotificationBearerToken()); preparedStatement.setString(4, backChannelUserDetails.getNotificationUrl()); preparedStatement.setString(5, backChannelUserDetails.getClientId()); preparedStatement.setString(6, backChannelUserDetails.getRedirectUrl()); preparedStatement.execute(); } catch (SQLException e) { handleException("Error occurred while inserting user details for : " + backChannelUserDetails.getMsisdn() + "in " + "BackChannel Scenario.", e); } catch (NamingException e) { throw new ConfigurationException("DataSource could not be found in mobile-connect.xml"); } finally { closeAllConnections(preparedStatement, connection); } }
From source file:com.wso2telco.dep.verificationhandler.verifier.DatabaseUtils.java
/** * Gets the API id./*from w w w . j a v a2 s . co m*/ * * @param apiContext the api name * @return the API id * @throws NamingException the naming exception * @throws SQLException the SQL exception */ public static String getAPIId(String apiContext, String apiVersion) throws NamingException, SQLException { String apiId = null; /// String sql = "select * from am_subscription"; Connection conn = null; PreparedStatement ps = null; ResultSet rs = null; try { String sql = "select API_ID from AM_API where CONTEXT = ? "; if (apiVersion != null) { sql += " AND API_VERSION = ?"; } conn = getAMDBConnection(); ps = conn.prepareStatement(sql); ps.setString(1, apiContext); if (apiVersion != null) { ps.setString(2, apiVersion); } rs = ps.executeQuery(); while (rs.next()) { apiId = rs.getString("API_ID"); } } catch (SQLException e) { log.error("Error occured while writing southbound record.", e); throw e; } catch (NamingException e) { log.error("Error while finding the Datasource.", e); throw e; } finally { APIMgtDBUtil.closeAllConnections(ps, conn, rs); } return apiId; }
From source file:com.wso2telco.gsma.authenticators.DBUtils.java
public static void incrementPinAttempts(String sessionId) throws SQLException, AuthenticatorException { Connection connection = null; PreparedStatement ps = null; String sql = "update multiplepasswords set attempts=attempts +1 where ussdsessionid = ?;"; connection = getConnectDBConnection(); ps = connection.prepareStatement(sql); ps.setString(1, sessionId); log.info(ps.toString());/*from w w w . java 2 s. co m*/ ps.execute(); if (connection != null) { connection.close(); } }
From source file:net.mindengine.oculus.frontend.service.report.filter.JdbcFilterDAO.java
@Override public long createFilter(Filter filter) throws Exception { String sql = "insert into filters (name, description, user_id, date, filter) values (?,?,?,?,?)"; PreparedStatement ps = getConnection().prepareStatement(sql); ps.setString(1, filter.getName()); ps.setString(2, filter.getDescription()); ps.setLong(3, filter.getUserId());//from w ww . j a v a 2s . co m ps.setTimestamp(4, new Timestamp(filter.getDate().getTime())); ps.setString(5, filter.getFilter()); logger.info(ps); ps.execute(); ResultSet rs = ps.getGeneratedKeys(); if (rs.next()) { return rs.getLong(1); } return 0; }
From source file:com.autentia.tnt.bill.migration.support.OriginalInformationRecoverer.java
/** * Recupera la suma total de todos los conceptos de todas las facturas del tipo que se envie por parametro * @param billType tipo de factura/* w ww .j a v a 2 s . co m*/ */ public static double getTotalFacturasOriginal(String billType) throws Exception { Connection con = null; PreparedStatement pstmt = null; ResultSet rs = null; LineNumberReader file = null; double result = -1; try { log.info("RECOVERING TOTAL FACTURAS " + billType + " ORIGINALES"); // connect to database Class.forName(BillToBillPaymentMigration.DATABASE_DRIVER); con = DriverManager.getConnection(BillToBillPaymentMigration.DATABASE_CONNECTION, BillToBillPaymentMigration.DATABASE_USER, BillToBillPaymentMigration.DATABASE_PASS); //NOSONAR con.setAutoCommit(false); // DATABASE_PASS vacio String sql = "SELECT sum((bb.units*bb.amount)*(1+(bb.iva/100))) as total from Bill b left join BillBreakDown bb on b.id=bb.billId, Organization o, Project p where b.projectId = p.id and p.organizationId = o.id and b.billType= ?"; pstmt = con.prepareStatement(sql); pstmt.setString(1, billType); rs = pstmt.executeQuery(); while (rs.next()) { result = rs.getDouble(1); log.info("\t" + result); } con.commit(); } catch (Exception e) { log.error("FAILED: WILL BE ROLLED BACK: ", e); if (con != null) { con.rollback(); } } finally { cierraFichero(file); liberaConexion(con, pstmt, rs); } return result; }
From source file:com.uiip.gviviani.esercizioweekend.interfaces.impl.DefaultPhoneDAO.java
@Override public boolean inserisciPhone(PhoneModel phone) { MysqlDataSource datasource = new MysqlDataSource(); datasource.setUser("root"); datasource.setPassword("root"); datasource.setUrl("jdbc:mysql://localhost:3306/Rubrica"); Connection connection = null; try {//from ww w . j av a 2 s . co m connection = datasource.getConnection(); String sql = "INSERT INTO telefono (name, brand, opsys, displaySize) VALUE " + "(?, ?, ?, ?);"; PreparedStatement stat = connection.prepareStatement(sql); stat.setString(1, phone.getNome()); stat.setString(2, phone.getBrand()); stat.setString(3, phone.getOpsys()); stat.setString(4, phone.getDisplay()); if (stat.executeUpdate() > 0) { return true; } } catch (SQLException e) { logger.error(e); } finally { DbUtils.closeQuietly(connection); } return false; }
From source file:com.leapfrog.sms.dao.impl.CourseDAOImpl.java
@Override public List<Course> search(String param) { final String parameter = param; PreparedStatementSetter setter = new PreparedStatementSetter() { @Override/*from www.j ava2s. c o m*/ public void setValues(PreparedStatement ps) throws SQLException { ps.setString(1, "%" + parameter + "%"); } }; return jdbcTemplate.query(SqlConstant.COURSE_SEARCH, setter, new RowMapper<Course>() { @Override public Course mapRow(ResultSet rs, int i) throws SQLException { return mapData(rs); } }); }
From source file:biz.vnc.zimbra.lighthistoryzimlet.MailhistoryReader.java
public String getRecord(String msgId) { JSONObject storejson = new JSONObject(); JSONArray jsonArray = new JSONArray(); try {// w w w . ja va 2s . c o m dbConnection = LocalDB.connect(LocalConfig.get().db_name); String query = "SELECT * FROM mail_log_internal WHERE message_id=?" + "ORDER BY logtime ASC"; PreparedStatement statement = dbConnection.prepareStatement(query); statement.setString(1, msgId.trim()); ResultSet resultSet = statement.executeQuery(); ZLog.info("biz_vnc_lightweight_history", "Read Message Id" + msgId); while (resultSet.next()) { JSONObject jsonObject = new JSONObject(); jsonObject.put("logtime", resultSet.getString("logtime")); if (resultSet.getString("from_localpart").equals("-") || resultSet.getString("from_domain").equals("-")) { jsonObject.put("from", "-"); } else { jsonObject.put("from", resultSet.getString("from_localpart") + "@" + resultSet.getString("from_domain")); } if (resultSet.getString("to_localpart").equals("-") || resultSet.getString("to_domain").equals("-")) { jsonObject.put("to", "-"); } else { jsonObject.put("to", resultSet.getString("to_localpart") + "@" + resultSet.getString("to_domain")); } jsonObject.put("moveto", resultSet.getString("foldername")); jsonObject.put("event", resultSet.getString("event")); jsonArray.add(jsonObject); } storejson.put("list", jsonArray); } catch (Exception e) { ZLog.err("mail-history", "getRecord: database query failed", e); } ZLog.info("biz_vnc_lightweight_history", "Recod Json :: " + storejson.toJSONString()); return storejson.toJSONString(); }
From source file:com.ywang.alone.handler.task.AuthTask.java
/** * { 'key':'2597aa1d37d432a','fid':'1020293' } * //from w w w . ja v a 2 s .c o m * @param param * @return */ private static String follow(String msg) { JSONObject jsonObject = AloneUtil.newRetJsonObject(); JSONObject param = JSON.parseObject(msg); String token = param.getString("key"); String userId = null; if (StringUtils.isEmpty(token)) { jsonObject.put("ret", Constant.RET.NO_ACCESS_AUTH); jsonObject.put("errCode", Constant.ErrorCode.NO_ACCESS_AUTH); jsonObject.put("errDesc", Constant.ErrorDesc.NO_ACCESS_AUTH); return jsonObject.toJSONString(); } Jedis jedis = JedisUtil.getJedis(); Long tokenTtl = jedis.ttl("TOKEN:" + token); if (tokenTtl == -1) { jsonObject.put("ret", Constant.RET.NO_ACCESS_AUTH); jsonObject.put("errCode", Constant.ErrorCode.NO_ACCESS_AUTH); jsonObject.put("errDesc", Constant.ErrorDesc.NO_ACCESS_AUTH); } else { userId = jedis.get("TOKEN:" + token); LoggerUtil.logMsg("uid is " + userId); } JedisUtil.returnJedis(jedis); if (StringUtils.isEmpty(userId)) { jsonObject.put("ret", Constant.RET.NO_ACCESS_AUTH); jsonObject.put("errCode", Constant.ErrorCode.NO_ACCESS_AUTH); jsonObject.put("errDesc", Constant.ErrorDesc.NO_ACCESS_AUTH); return jsonObject.toJSONString(); } DruidPooledConnection conn = null; PreparedStatement stmt = null; try { conn = DataSourceFactory.getInstance().getConn(); conn.setAutoCommit(false); stmt = conn.prepareStatement("insert into follow (USER_ID, FOLLOWED_ID, `TIME`) VALUES (?,?,?)", Statement.RETURN_GENERATED_KEYS); stmt.setString(1, userId); stmt.setString(2, param.getString("fid").trim()); stmt.setLong(3, System.currentTimeMillis()); int result = stmt.executeUpdate(); if (result != 1) { jsonObject.put("ret", Constant.RET.UPDATE_DB_FAIL); jsonObject.put("errCode", Constant.ErrorCode.UPDATE_DB_FAIL); jsonObject.put("errDesc", Constant.ErrorDesc.UPDATE_DB_FAIL); } conn.commit(); conn.setAutoCommit(true); } catch (SQLException e) { LoggerUtil.logServerErr(e); jsonObject.put("ret", Constant.RET.SYS_ERR); jsonObject.put("errCode", Constant.ErrorCode.SYS_ERR); jsonObject.put("errDesc", Constant.ErrorDesc.SYS_ERR); } finally { try { if (null != stmt) { stmt.close(); } if (null != conn) { conn.close(); } } catch (SQLException e) { LoggerUtil.logServerErr(e.getMessage()); } } return jsonObject.toJSONString(); }