List of usage examples for java.sql PreparedStatement setString
void setString(int parameterIndex, String x) throws SQLException;
String
value. From source file:com.l2jfree.gameserver.model.entity.events.DM.java
public static void saveData() { Connection con = null;//w w w. ja va 2 s . c o m try { con = L2DatabaseFactory.getInstance().getConnection(con); PreparedStatement statement; statement = con.prepareStatement("Delete from dm"); statement.execute(); statement.close(); statement = con.prepareStatement( "INSERT INTO dm (eventName, eventDesc, joiningLocation, minlvl, maxlvl, npcId, npcX, npcY, npcZ, rewardId, rewardAmount, color, playerX, playerY, playerZ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); statement.setString(1, _eventName); statement.setString(2, _eventDesc); statement.setString(3, _joiningLocationName); statement.setInt(4, _minlvl); statement.setInt(5, _maxlvl); statement.setInt(6, _npcId); statement.setInt(7, _npcX); statement.setInt(8, _npcY); statement.setInt(9, _npcZ); statement.setInt(10, _rewardId); statement.setInt(11, _rewardAmount); statement.setInt(12, _playerColors); statement.setInt(13, _playerX); statement.setInt(14, _playerY); statement.setInt(15, _playerZ); statement.execute(); statement.close(); } catch (Exception e) { _log.error("Exception: DM.saveData(): ", e); } finally { L2DatabaseFactory.close(con); } }
From source file:com.apress.prospringintegration.springenterprise.stocks.dao.jdbc.PSStockUpdater.java
public PreparedStatement createPreparedStatement(Connection connection) throws SQLException { String sql = "UPDATE STOCKS SET SYMBOL = ?, INVENTORY_CODE = ?, PRICE_PER_SHARE = ?," + " QUANTITY_AVAILABLE = ?, EXCHANGE_ID = ?, PURCHASE_DATE = ? where ID = ?"; PreparedStatement ps = connection.prepareStatement(sql); ps.setString(1, stock.getSymbol()); ps.setString(2, stock.getInventoryCode()); ps.setFloat(3, stock.getSharePrice()); ps.setFloat(4, stock.getQuantityAvailable()); ps.setString(5, stock.getExchangeId()); ps.setDate(6, new java.sql.Date(stock.getPurchaseDate().getTime())); ps.setInt(7, stock.getId());// w w w .j a v a 2 s .com return ps; }
From source file:ece356.UserDBAO.java
public static void writeReview(ReviewData review) throws ClassNotFoundException, SQLException, NamingException { Connection con = null;/*w ww .j a va2 s . c om*/ PreparedStatement pstmt = null; try { con = getConnection(); pstmt = con.prepareStatement( "INSERT INTO review (doc_username, patient_username, date, rating, comment) VALUES (?, ?, NOW(), ?, ?);"); pstmt.setString(1, review.getDoctorUsername()); pstmt.setString(2, review.getPatientUsername()); pstmt.setInt(3, review.getRating()); pstmt.setString(4, review.getComment()); pstmt.executeUpdate(); } finally { if (pstmt != null) { pstmt.close(); } if (con != null) { con.close(); } } }
From source file:com.wso2telco.dbUtil.DataBaseConnectUtils.java
/** * Get SP related configurations//from w w w . j av a2 s .c om * * @param sessionId * @return * @throws ConfigurationException * @throws CommonAuthenticatorException */ public static BackChannelRequestDetails getRequestDetailsBySessionId(String sessionId) throws ConfigurationException, CommonAuthenticatorException { Connection connection = null; PreparedStatement preparedStatement = null; BackChannelRequestDetails backchannelRequestDetails = null; ResultSet resultSet = null; String getUserDetailsQuery = "select * FROM backchannel_request_details where session_id=?"; try { connection = getConnectDBConnection(); if (log.isDebugEnabled()) { log.debug("Executing the query " + getUserDetailsQuery); } preparedStatement = connection.prepareStatement(getUserDetailsQuery); preparedStatement.setString(1, sessionId); resultSet = preparedStatement.executeQuery(); if (resultSet.next()) { backchannelRequestDetails = new BackChannelRequestDetails(); backchannelRequestDetails.setSessionId(resultSet.getString("session_id")); backchannelRequestDetails.setAuthCode(resultSet.getString("auth_code")); backchannelRequestDetails.setCorrelationId(resultSet.getString("correlation_id")); backchannelRequestDetails.setMsisdn(resultSet.getString("msisdn")); backchannelRequestDetails .setNotificationBearerToken(resultSet.getString("notification_bearer_token")); backchannelRequestDetails.setNotificationUrl(resultSet.getString("notification_url")); backchannelRequestDetails.setClientId(resultSet.getString("client_id")); } } catch (SQLException e) { handleException("Error occurred while fetching SP related data for the Session Id: " + sessionId, e); } catch (NamingException e) { throw new ConfigurationException("DataSource could not be found in mobile-connect.xml"); } finally { closeAllConnections(preparedStatement, connection, resultSet); } return backchannelRequestDetails; }
From source file:org.waarp.common.database.data.AbstractDbData.java
/** * Set Value into PreparedStatement/*w ww . j a v a 2s . c om*/ * * @param ps * @param value * @param rank * >= 1 * @throws WaarpDatabaseSqlException */ static public void setTrueValue(PreparedStatement ps, DbValue value, int rank) throws WaarpDatabaseSqlException { try { switch (value.type) { case Types.VARCHAR: if (value.value == null) { ps.setNull(rank, Types.VARCHAR); break; } ps.setString(rank, (String) value.value); break; case Types.LONGVARCHAR: if (value.value == null) { ps.setNull(rank, Types.LONGVARCHAR); break; } ps.setString(rank, (String) value.value); break; case Types.BIT: if (value.value == null) { ps.setNull(rank, Types.BIT); break; } ps.setBoolean(rank, (Boolean) value.value); break; case Types.TINYINT: if (value.value == null) { ps.setNull(rank, Types.TINYINT); break; } ps.setByte(rank, (Byte) value.value); break; case Types.SMALLINT: if (value.value == null) { ps.setNull(rank, Types.SMALLINT); break; } ps.setShort(rank, (Short) value.value); break; case Types.INTEGER: if (value.value == null) { ps.setNull(rank, Types.INTEGER); break; } ps.setInt(rank, (Integer) value.value); break; case Types.BIGINT: if (value.value == null) { ps.setNull(rank, Types.BIGINT); break; } ps.setLong(rank, (Long) value.value); break; case Types.REAL: if (value.value == null) { ps.setNull(rank, Types.REAL); break; } ps.setFloat(rank, (Float) value.value); break; case Types.DOUBLE: if (value.value == null) { ps.setNull(rank, Types.DOUBLE); break; } ps.setDouble(rank, (Double) value.value); break; case Types.VARBINARY: if (value.value == null) { ps.setNull(rank, Types.VARBINARY); break; } ps.setBytes(rank, (byte[]) value.value); break; case Types.DATE: if (value.value == null) { ps.setNull(rank, Types.DATE); break; } ps.setDate(rank, (Date) value.value); break; case Types.TIMESTAMP: if (value.value == null) { ps.setNull(rank, Types.TIMESTAMP); break; } ps.setTimestamp(rank, (Timestamp) value.value); break; case Types.CLOB: if (value.value == null) { ps.setNull(rank, Types.CLOB); break; } ps.setClob(rank, (Reader) value.value); break; case Types.BLOB: if (value.value == null) { ps.setNull(rank, Types.BLOB); break; } ps.setBlob(rank, (InputStream) value.value); break; default: throw new WaarpDatabaseSqlException("Type not supported: " + value.type + " at " + rank); } } catch (ClassCastException e) { throw new WaarpDatabaseSqlException("Setting values casting error: " + value.type + " at " + rank, e); } catch (SQLException e) { DbSession.error(e); throw new WaarpDatabaseSqlException("Setting values in error: " + value.type + " at " + rank, e); } }
From source file:com.mycompany.spring_chatdemo.ConnectDB.java
public void insertDB(Message message) throws SQLException { try {// w w w. j a v a 2 s. c o m String query = "INSERT INTO " + table + " VALUES (?, ?, ?)"; connection = dataSource.getConnection(); PreparedStatement ps = connection.prepareStatement(query); ps.setString(1, message.getFrom()); ps.setString(2, message.getTo()); ps.setString(3, message.getMessage()); ps.executeUpdate(); ps.close(); } catch (SQLException ex) { Logger.getLogger(ConnectDB.class.getName()).log(Level.SEVERE, null, ex); } finally { if (connection != null) connection.close(); } }
From source file:com.wso2telco.dbUtil.DataBaseConnectUtils.java
/** * Get user details in Back Channeling Scenario using sessionID * * @param sessionId Id of the session// w w w. ja va 2 s .c om */ public static BackChannelRequestDetails getBackChannelUserDetails(String sessionId) throws ConfigurationException, CommonAuthenticatorException { Connection connection = null; PreparedStatement preparedStatement = null; BackChannelRequestDetails backChannelRequestDetails = null; ResultSet resultSet = null; String getUserDetailsQuery = "select * from backchannel_request_details where session_id=?"; try { connection = getConnectDBConnection(); if (log.isDebugEnabled()) { log.debug("Executing the query " + getUserDetailsQuery); } preparedStatement = connection.prepareStatement(getUserDetailsQuery); preparedStatement.setString(1, sessionId); resultSet = preparedStatement.executeQuery(); if (resultSet.next()) { backChannelRequestDetails = new BackChannelRequestDetails(); backChannelRequestDetails.setCorrelationId(resultSet.getString("correlation_id")); backChannelRequestDetails.setSessionId(resultSet.getString("session_id")); backChannelRequestDetails.setNotificationUrl(resultSet.getString("notification_url")); backChannelRequestDetails .setNotificationBearerToken(resultSet.getString("notification_bearer_token")); backChannelRequestDetails.setAuthCode(resultSet.getString("auth_code")); backChannelRequestDetails.setMsisdn(resultSet.getString("msisdn")); backChannelRequestDetails.setRequestIniticatedTime(resultSet.getString("request_initiated_time")); backChannelRequestDetails.setClientId(resultSet.getString("client_id")); backChannelRequestDetails.setRedirectUrl(resultSet.getString("redirect_url")); } } catch (SQLException e) { handleException("Error occurred while getting user related details for session: " + sessionId + "in BackChannel " + "Scenario.", e); } catch (NamingException e) { throw new ConfigurationException("DataSource could not be found in mobile-connect.xml"); } finally { closeAllConnections(preparedStatement, connection, resultSet); } return backChannelRequestDetails; }
From source file:com.wso2telco.dbUtil.DataBaseConnectUtils.java
/** * Get SP related configurations// w w w.j av a2s . c om * * @param correlationId * @return * @throws ConfigurationException * @throws CommonAuthenticatorException */ public static BackChannelRequestDetails getRequestDetailsById(String correlationId) throws ConfigurationException, CommonAuthenticatorException { Connection connection = null; PreparedStatement preparedStatement = null; BackChannelRequestDetails backchannelRequestDetails = null; ResultSet resultSet = null; String getUserDetailsQuery = "select * FROM backchannel_request_details where correlation_id=?"; try { connection = getConnectDBConnection(); if (log.isDebugEnabled()) { log.debug("Executing the query " + getUserDetailsQuery); } preparedStatement = connection.prepareStatement(getUserDetailsQuery); preparedStatement.setString(1, correlationId); resultSet = preparedStatement.executeQuery(); if (resultSet.next()) { backchannelRequestDetails = new BackChannelRequestDetails(); backchannelRequestDetails.setSessionId(resultSet.getString("session_id")); backchannelRequestDetails.setAuthCode(resultSet.getString("auth_code")); backchannelRequestDetails.setCorrelationId(resultSet.getString("correlation_id")); backchannelRequestDetails.setMsisdn(resultSet.getString("msisdn")); backchannelRequestDetails .setNotificationBearerToken(resultSet.getString("notification_bearer_token")); backchannelRequestDetails.setNotificationUrl(resultSet.getString("notification_url")); backchannelRequestDetails.setClientId(resultSet.getString("client_id")); } } catch (SQLException e) { handleException( "Error occurred while fetching SP related data for the Correlation Id: " + correlationId, e); } catch (NamingException e) { throw new ConfigurationException("DataSource could not be found in mobile-connect.xml"); } finally { closeAllConnections(preparedStatement, connection, resultSet); } return backchannelRequestDetails; }
From source file:com.krawler.esp.servlets.FileImporterServlet.java
public static void fildoc(String docid, String docname, String projid, String svnName, String userid, long size) throws ServiceException { PreparedStatement pstmt = null; String sql = null;/*from w w w .j a v a 2s.c o m*/ Connection conn = null; try { conn = DbPool.getConnection(); java.util.Date d = new java.util.Date(); java.sql.Timestamp docdatemod = new Timestamp(d.getTime()); String currentStoreIndex = StorageHandler.GetCurrentStorageIndex(); sql = "INSERT INTO docs(docid, docname, docdatemod, " + "userid,svnname,storageindex,docsize) VALUES (?,?,?,?,?,?,?)"; pstmt = conn.prepareStatement(sql); pstmt.setString(1, docid); pstmt.setString(2, docname); pstmt.setObject(3, docdatemod); pstmt.setObject(4, userid); pstmt.setString(5, svnName); pstmt.setString(6, currentStoreIndex); pstmt.setObject(7, size); pstmt.executeUpdate(); sql = "insert into docprerel (docid,userid,permission) values(?,?,?)"; pstmt = conn.prepareStatement(sql); pstmt.setString(1, docid); pstmt.setString(2, projid); pstmt.setObject(3, "8"); pstmt.executeUpdate(); conn.commit(); } catch (ServiceException ex) { DbPool.quietRollback(conn); throw ServiceException.FAILURE("FileImporterServlet.fildoc", ex); } catch (Exception ex) { DbPool.quietRollback(conn); throw ServiceException.FAILURE("FileImporterServlet.fildoc", ex); } finally { DbPool.quietClose(conn); } }
From source file:com.wso2telco.dep.verificationhandler.verifier.DatabaseUtils.java
/** * Check white listed./* w w w .ja va 2s .com*/ * * @param MSISDN the msisdn * @param applicationId the application id * @param subscriptionId the subscription id * @param apiId the api id * @return the white list result * @throws SQLException the SQL exception * @throws NamingException the naming exception */ public static WhiteListResult checkWhiteListed(String MSISDN, String applicationId, String subscriptionId, String apiId) throws SQLException, NamingException { WhiteListResult whiteListResult = null; String sql = "SELECT * FROM `subscription_WhiteList` WHERE \n" + //check with all value mean MSISDN to subscription "(`subscriptionID` = ? AND `msisdn` = ? AND `api_id` = ? AND `application_id` = ?) OR \n" + //check with out subscription. but match API,MSISDN and ApplicationID "(`subscriptionID` IS NULL AND `msisdn` = ? AND `api_id` = ? AND `application_id` = ?) OR \n" + //check with only subscription ID and MSISDN "(`subscriptionID` = ? AND `msisdn` = ? AND `api_id` IS NULL AND `application_id` IS NULL ) OR \n" + //match specific MSISDN to whole application "(`subscriptionID` IS NULL AND `msisdn` = ? AND `api_id` IS NULL AND `application_id` = ?) OR \n" + //Match applicaiton only. it mean application can use any API, MSISDN without whitelist individual "(`subscriptionID` IS NULL AND `msisdn` IS NULL AND `api_id` IS NULL AND `application_id` = ?) OR \n" + //Match application's API only. it mean application can use specific API with any MSISDN without whitelist individual "(`subscriptionID` IS NULL AND `msisdn` IS NULL AND `api_id` = ? AND `application_id` = ?) LIMIT 0,1 "; Connection conn = null; PreparedStatement ps = null; ResultSet rs = null; try { conn = getStatsDBConnection(); ps = conn.prepareStatement(sql); //"(`subscriptionID` = ? AND `msisdn` = ? AND `api_id` = ? AND `application_id` = >) OR \n" + ps.setString(1, subscriptionId); ps.setString(2, MSISDN); ps.setString(3, apiId); ps.setString(4, applicationId); //"(`subscriptionID` = null AND `msisdn` = ? AND `api_id` = ? AND `application_id` = ?) OR\n" ps.setString(5, MSISDN); ps.setString(6, apiId); ps.setString(7, applicationId); // "(`subscriptionID` = ? AND `msisdn` = ? AND `api_id` = null AND `application_id` = null) OR \n" + ps.setString(8, subscriptionId); ps.setString(9, MSISDN); // "(`subscriptionID` = null AND `msisdn` = ? AND `api_id` = null AND `application_id` = ?) OR \n" + ps.setString(10, MSISDN); ps.setString(11, applicationId); //"(`subscriptionID` = null AND `msisdn` = null AND `api_id` = null AND `application_id` = ?) OR \n" + ps.setString(12, applicationId); // "(`subscriptionID` = null AND `msisdn` = null AND `api_id` = ? AND `application_id` = ?) "; ps.setString(13, apiId); ps.setString(14, applicationId); rs = ps.executeQuery(); if (rs != null) { while (rs.next()) { whiteListResult = new WhiteListResult(); String msisdnTable = rs.getString("msisdn"); whiteListResult.setApi_id(rs.getString("api_id")); whiteListResult.setApplication_id(rs.getString("application_id")); whiteListResult.setSubscriptionID(rs.getString("subscriptionID")); whiteListResult.setMsisdn(msisdnTable); } } // log.info(ps); } 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 whiteListResult; }