List of usage examples for java.sql PreparedStatement toString
public String toString()
From source file:com.wso2telco.dep.reportingservice.dao.WorkflowDAO.java
/** * Save subscription charge rate./*w w w .ja v a 2 s. c o m*/ * * @param appId the app id * @param apiId the api id * @param opName the op name * @throws Exception the exception */ public void saveSubscriptionChargeRate(String appId, String apiId, String opName) throws Exception { Connection conn = null; ResultSet rs = null; PreparedStatement ps = null; try { String apiName = apiManagerDAO.getApiNameById(Integer.valueOf(apiId)); conn = DbUtils.getDbConnection(DataSourceNames.WSO2AM_STATS_DB); String sql = "SELECT operation_id,default_rate FROM " + ReportingTable.API_OPERATION_TYPES + " WHERE api=?"; ps = conn.prepareStatement(sql); ps.setString(1, apiName); log.debug("SQL (PS) ---> " + ps.toString()); rs = ps.executeQuery(); while (rs.next()) { Integer opId = Integer.parseInt(rs.getString("operation_id")); String defaultRate = rs.getString("default_rate"); String query = "INSERT INTO " + ReportingTable.SUBSCRIPTION_RATES + " (`application_id`, `api_id`, `operator_name`, `rate_id_sb`, `operation_id`) VALUES (?, ?, ?, ?, ?)"; ps = conn.prepareStatement(query); ps.setInt(1, Integer.parseInt(appId)); ps.setInt(2, Integer.parseInt(apiId)); ps.setString(3, opName); ps.setString(4, defaultRate); ps.setInt(5, opId); ps.executeUpdate(); } } catch (SQLException e) { handleException("Error in Creating subscription charge rate : " + e.getMessage(), e); } finally { DbUtils.closeAllConnections(ps, conn, rs); } }
From source file:com.wso2telco.dep.reportingservice.dao.WorkflowDAO.java
/** * Save subscription charge rate nb./*from w w w .j a va 2s . com*/ * * @param appId the app id * @param apiId the api id * @throws Exception the exception */ public void saveSubscriptionChargeRateNB(String appId, String apiId) throws Exception { Connection conn = null; ResultSet rs = null; PreparedStatement ps = null; try { String apiName = apiManagerDAO.getApiNameById(Integer.valueOf(apiId)); conn = DbUtils.getDbConnection(DataSourceNames.WSO2AM_STATS_DB); String sql = "SELECT operation_id,default_rate FROM " + ReportingTable.API_OPERATION_TYPES + " WHERE api=?"; ps = conn.prepareStatement(sql); ps.setString(1, apiName); log.debug("SQL (PS) ---> " + ps.toString()); rs = ps.executeQuery(); while (rs.next()) { Integer opId = Integer.parseInt(rs.getString("operation_id")); String defaultRate = rs.getString("default_rate"); String query = "INSERT INTO " + ReportingTable.SUBSCRIPTION_RATES_NB + " (`application_id`, `api_id`, `rate_id_nb`, `operation_id`) VALUES (?, ?, ?, ?)"; ps = conn.prepareStatement(query); ps.setInt(1, Integer.parseInt(appId)); ps.setInt(2, Integer.parseInt(apiId)); ps.setString(3, defaultRate); ps.setInt(4, opId); ps.executeUpdate(); } } catch (SQLException e) { handleException("Error in Creating subscription charge rate : " + e.getMessage(), e); } finally { DbUtils.closeAllConnections(ps, conn, rs); } }
From source file:com.amazonbird.announce.ProductMgrImpl.java
public void removeProduct(long id) { Connection connection = null; PreparedStatement ps = null; try {//ww w. j ava 2 s . co m connection = dbMgr.getConnection(); ps = connection.prepareStatement(DELETE_PRODUCT); ps.setLong(1, id); ps.executeUpdate(); logger.debug(DBConstants.QUERY_EXECUTION_SUCC + ps.toString()); } catch (SQLException ex) { logger.error(DBConstants.QUERY_EXECUTION_FAIL + ps.toString(), ex); } finally { dbMgr.closeResources(connection, ps, null); } }
From source file:com.amazonbird.announce.ProductMgrImpl.java
private void setProductActiveInactive(long id, boolean active) { Connection connection = null; PreparedStatement ps = null; try {//from w ww . j av a 2s . co m connection = dbMgr.getConnection(); ps = connection.prepareStatement(SET_PRODUCT_ACTIVE); ps.setBoolean(1, active); ps.setLong(2, id); ps.executeUpdate(); logger.debug(DBConstants.QUERY_EXECUTION_SUCC + ps.toString()); } catch (SQLException ex) { logger.error(DBConstants.QUERY_EXECUTION_FAIL + ps.toString(), ex); } finally { dbMgr.closeResources(connection, ps, null); } }
From source file:uk.ac.cam.cl.dtg.segue.dao.users.PgUserGroupPersistenceManager.java
@Override public UserGroup editGroup(final UserGroup group) throws SegueDatabaseException { Validate.notNull(group.getId());/*w ww.j a v a 2s . c o m*/ PreparedStatement pst; try (Connection conn = database.getDatabaseConnection()) { pst = conn.prepareStatement("UPDATE groups SET group_name=?, owner_id=?, created=? WHERE id = ?;"); pst.setString(1, group.getGroupName()); pst.setLong(2, group.getOwnerId()); pst.setTimestamp(3, new Timestamp(group.getCreated().getTime())); pst.setLong(4, group.getId()); log.debug(pst.toString()); if (pst.executeUpdate() == 0) { throw new SegueDatabaseException("Unable to save group."); } return this.findById(group.getId()); } catch (SQLException e) { throw new SegueDatabaseException("Postgres exception", e); } }
From source file:com.amazonbird.announce.ProductMgrImpl.java
public void addProductPicture(long productId, String url) { Connection connection = null; PreparedStatement ps = null; ResultSet rs = null;//from w w w . j a v a 2s. c o m try { connection = dbMgr.getConnection(); ps = connection.prepareStatement(ADD_PRODUCT_PICTURE); ps.setLong(1, productId); ps.setString(2, url); ps.executeUpdate(); logger.debug(DBConstants.QUERY_EXECUTION_SUCC + ps.toString()); } catch (SQLException ex) { logger.error(DBConstants.QUERY_EXECUTION_FAIL + ps.toString(), ex); } finally { dbMgr.closeResources(connection, ps, rs); } }
From source file:com.alibaba.wasp.jdbc.TestPreparedStatement.java
public void testToString() throws SQLException { PreparedStatement prep = conn.prepareStatement("call 1"); assertTrue(prep.toString().endsWith(": call 1")); prep = conn.prepareStatement("call ?"); assertTrue(prep.toString().endsWith(": call ?")); prep.setString(1, "Hello World"); assertTrue(prep.toString().endsWith(": call ? {1: 'Hello World'}")); }
From source file:com.amazonbird.announce.ProductMgrImpl.java
public int getActiveProductCount() { Connection connection = null; PreparedStatement ps = null; ResultSet rs = null;/*from www .j a v a 2s . c o m*/ int count = 0; try { connection = dbMgr.getConnection(); ps = connection.prepareStatement(COUNT_ACTIVE_PRODUCT); rs = ps.executeQuery(); if (rs.next()) { count = rs.getInt(1); } logger.debug(DBConstants.QUERY_EXECUTION_SUCC + ps.toString()); } catch (SQLException ex) { logger.error(DBConstants.QUERY_EXECUTION_FAIL + ps.toString(), ex); } finally { dbMgr.closeResources(connection, ps, rs); } return count; }
From source file:org.apache.hawq.ranger.service.HawqClient.java
private List<String> queryHawq(String userInput, String columnName, String query, String database) throws SQLException { List<String> result = new ArrayList<>(); PreparedStatement preparedStatement = null; ResultSet resultSet = null;// w w w . j a va 2 s. co m Connection conn = null; try { conn = getConnection(connectionProperties, database); preparedStatement = handleWildcardPreparedStatement(userInput, query, conn); if (LOG.isDebugEnabled()) { LOG.debug("<== HawqClient.queryHawq Starting query: " + preparedStatement.toString()); } resultSet = preparedStatement.executeQuery(); while (resultSet.next()) { result.add(resultSet.getString(columnName)); } if (LOG.isDebugEnabled()) { LOG.debug("<== HawqClient.queryHawq Query result: " + result.toString()); } } catch (SQLException e) { LOG.error( "<== HawqClient.queryHawq Error: Failed to get result from query: " + query + ", Error: " + e); throw e; } finally { closeResultSet(resultSet); closeStatement(preparedStatement); closeConnection(conn); } return result; }
From source file:at.alladin.rmbt.controlServer.StatusResource.java
@Post("json") public String request(final String entity) { addAllowOrigin();/* w ww . j a va 2 s . co m*/ JSONObject request = null; final ErrorList errorList = new ErrorList(); final JSONObject answer = new JSONObject(); String answerString; final String clientIpRaw = getIP(); final InetAddress clientAddress = InetAddresses.forString(clientIpRaw); System.out.println(MessageFormat.format(labels.getString("NEW_STATUS_REQ"), clientIpRaw)); double geolat = 0; double geolong = 0; float geoaccuracy = 0; // in m double geoaltitude = 0; float geospeed = 0; // in m/s String telephonyNetworkSimOperator = ""; String telephonyNetworkSimCountry = ""; boolean homeCountry = true; if (entity != null && !entity.isEmpty()) { // try parse the string to a JSON object try { // debug parameters sent request = new JSONObject(entity); System.out.println(request.toString(4)); /* sample request Status request from 46.206.21.94 { "accuracy": 65, "altitude": 233.5172119140625, "client": "RMBT", "device": "iPhone", "language": "de", "lat": 48.19530995813387, "long": 16.29190354953834, "model": "iPhone5,2", "name": "RMBT", "network_type": 2, "os_version": "8.1.2", "plattform": "iOS", "softwareRevision": "next-858-8491858", "softwareVersion": "1.3.7", "softwareVersionCode": "1307", "speed": 0, "telephony_network_sim_country": "at", "telephony_network_sim_operator": "232-01", "telephony_network_sim_operator_name": "A1", "time": 1418241092784, "timezone": "Europe/Vienna", "type": "MOBILE", "uuid": "1cf594f6-0d07-4ff6-acd3-3d78ed9c0274", "version": "0.3" } */ geolat = request.optDouble("lat", 0); geolong = request.optDouble("long", 0); geoaccuracy = (float) request.optDouble("accuracy", 0); geoaltitude = request.optDouble("altitude", 0); geospeed = (float) request.optDouble("speed", 0); telephonyNetworkSimOperator = request.optString("telephony_network_sim_operator", ""); telephonyNetworkSimCountry = request.optString("telephony_network_sim_country", ""); } catch (final JSONException e) { errorList.addError("ERROR_REQUEST_JSON"); System.out.println("Error parsing JSON Data " + e.toString()); } } else { errorList.addErrorString("Expected request is missing."); } /* * * wb_a2 = 'AT' (2 digit country code) * ne_50m_admin_0_countries (SRID 900913 Mercator) * lat/long (SRID 4326 WGS84) * * SELECT st_contains(the_geom, ST_transform(ST_GeomFromText('POINT(56.391944 48.218056)',4326),900913)) home_country * FROM ne_50m_admin_0_countries * WHERE wb_a2='AT'; * * * */ try { PreparedStatement st; st = conn.prepareStatement( " SELECT st_contains(the_geom, ST_TRANSFORM(ST_GeomFromText( ? ,4326),900913)) home_country " + " FROM ne_50m_admin_0_countries " + " WHERE wb_a2 = ? "); int i = 1; final String point = "POINT(" + String.valueOf(geolong) + " " + String.valueOf(geolat) + ")"; st.setObject(i++, point); st.setObject(i++, telephonyNetworkSimCountry.toUpperCase()); //debug query System.out.println(st.toString()); final ResultSet rs = st.executeQuery(); if (rs.next()) // result only available if country (wb_a2) is found in ne_50_admmin_0_countries homeCountry = rs.getBoolean("home_country"); } catch (final SQLException e) { errorList.addError("ERROR_DB_GENERAL"); e.printStackTrace(); } try { answer.put("home_country", homeCountry); answer.putOpt("error", errorList.getList()); } catch (final JSONException e) { System.out.println("Error saving ErrorList: " + e.toString()); } answerString = answer.toString(); return answerString; }