} // The overloaded executeUpdate on the Statement object (which we // extend) is not valid for PreparedStatement or CallableStatement // objects. public int executeUpdate( String sql) throws SQLException { throw new SQLException(”Method is not valid”); } // The overloaded execute on the Statement object (which we // extend) is not valid for PreparedStatement or CallableStatement // objects. public boolean execute( String sql) throws SQLException { throw new SQLException(”Method is not valid”); } Setting Parameter Values The PreparedStatement class introduces a series of set methods to set the value of a specified parameter. Take the following SQL statement: INSERT INTO FOO VALUES (?, ?, ?) If this statement was used in creating a PreparedStatement object, you would need to set the value of each parameter before executing it. In the SimpleText driver, parameter values are kept in a Hashtable. The Hashtable contains the parameter number as the key, and a CommonValue object as the data object. By using a CommonValue object, the application can set the parameter using any one of the supported data types, and we can coerce the data into the format that we need in order to bind the parameter. Here s the code for the setString method: public void setString( int parameterIndex, String x) throws SQLException { // Validate the parameter index verify(parameterIndex); // Put the parameter into the boundParams Hashtable boundParams.put(new Integer(parameterIndex), x); } The verify method validates that the given parameter index is valid for the current prepared statement, and also clears any previously bound value for that parameter index: protected void verify( int parameterIndex) throws SQLException {
We strive to offer the highest quality service while maintaining a cheap and discount price structure. For your company, ecommerce, or personal web hosting needs, we offer the best solution.Trust us and please check quality web hosting services.

Leave a Reply