JavaSercer Pages 17.2.1 The SQLCommandBean and Value Classes

JavaSercer Pages 17.2.1 The SQLCommandBean and Value Classes The SQLCommandBean has three write-only properties. Example 17.3 shows the beginning of the class file with the setter methods. Example 17.3. SQLCommandBean Property Setter Methods package com.ora.jsp.sql; import java.util.*; import java.sql.*; import com.ora.jsp.sql.value.*; public class SQLCommandBean { private Connection conn; private String sqlValue; private Vector values; private boolean isExceptionThrown = false; public void setConnection(Connection conn) { this.conn = conn; } public void setSqlValue(String sqlValue) { this.sqlValue = sqlValue; } public void setValues(Vector values) { this.values = values; } … The connection property holds the Connection to use, and the sqlValue property is set to the SQL statement to execute, with question marks as placeholders for variable values, if any. The placeholders are then replaced with the values defined by the values property, a Vector with one com.ora.jsp.sql.Value object per placeholder. Before we look at the other SQLCommandBean methods, let’s look at the Value class. The Value class is an abstract class used as a superclass for classes representing specific Java types, as shown in Figure 17.3. It contains default implementations of methods for getting the specific type of value a subclass represents. Example 17.4 shows two of the methods. Example 17.4. Two Value Class Methods public abstract class Value { public BigDecimal getBigDecimal( ) throws UnsupportedConversionException { throw new UnsupportedConversionException( “No conversion to BigDecimal”); } public boolean getBoolean( ) throws UnsupportedConversionException { throw new UnsupportedConversionException( “No conversion to boolean”); } … The default implementation for each method simply throws a com.ora.jsp.sql.UnsupportedConversionException . Each subclass implements the method that returns the value of the type it represents, as well as the getString( ) method. The getString( ) method returns the value converted to a String. Example 17.5 shows the com.ora.jsp.sql.value.IntValue subclass. Example 17.5. The IntValue Class package com.ora.jsp.sql.value; import com.ora.jsp.sql.Value; public class IntValue extends Value { private int value; public IntValue(int value) { this.value = value; } page 243

Hint: If you are looking for very good and affordable webspace to host and run your java hosting application check Sandzak.com java web hosting provider

Comments are closed.