public interface TypeHandlerCallback
Here's a simple example of a boolean handler that uses "Yes" and "No".
public class YesNoBoolTypeHandlerCallback implements TypeHandlerCallback {
private static final String YES = "Yes";
private static final String NO = "No";
public Object getResult(ResultGetter getter) throws SQLException {
String s = getter.getString();
if (YES.equalsIgnoreCase(s)) {
return new Boolean (true);
} else if (NO.equalsIgnoreCase(s)) {
return new Boolean (false);
} else {
throw new SQLException ("Unexpected value " + s + " found where "+YES+" or "+NO+" was expected.");
}
}
public void setParameter(ParameterSetter setter, Object parameter) throws SQLException {
boolean b = ((Boolean)parameter).booleanValue();
if (b) {
setter.setString(YES);
} else {
setter.setString(NO);
}
}
public Object valueOf(String s) {
if (YES.equalsIgnoreCase(s)) {
return new Boolean (true);
} else if (NO.equalsIgnoreCase(s)) {
return new Boolean (false);
} else {
throw new SQLException ("Unexpected value " + s + " found where "+YES+" or "+NO+" was expected.");
}
}
}
| Modifier and Type | Method and Description |
|---|---|
Object |
getResult(ResultGetter getter)
Performs processing on a value before after it has been retrieved from a ResultSet.
|
void |
setParameter(ParameterSetter setter,
Object parameter)
Performs processing on a value before it is used to set the parameter of a PreparedStatement.
|
Object |
valueOf(String s)
Casts the string representation of a value into a type recognized by this type handler.
|
void setParameter(ParameterSetter setter, Object parameter) throws SQLException
setter - The interface for setting the value on the PreparedStatement.parameter - The value to be set.SQLException - If any error occurs.Object getResult(ResultGetter getter) throws SQLException
getter - The interface for getting the value from the ResultSet.SQLException - If any error occurs.Object valueOf(String s)
s - A string representation of a valid value for this type.Copyright © 2084–2018 dukeware.com. All rights reserved.