public class ServletHelpers extends Object
Modifier and Type | Field and Description |
---|---|
protected DatabaseProperties |
data |
Constructor and Description |
---|
ServletHelpers(DatabaseProperties dataValue) |
Modifier and Type | Method and Description |
---|---|
static Date |
buildDate(int year,
int month,
int day)
Construct an SQL date using the year, month, and day
|
static Date |
buildDate(String yearValue,
String monthValue,
String dayValue)
Construct an SQL date using the year, month, and day
|
static String |
doubleDoubleQuotes(String value)
Replace occurrences of double quotes with two
double quote characters.
|
static String |
escapeDoubleQuotes(String value)
Replace occurrences of double quotes with a back slash followed by
a double quote.
|
static String |
formatElapsedTime(long startTime)
This method is intended to help in showing the elapsed time for
generating a page.
|
static float |
getFloatValue(ResultSet rs,
String columnName)
Return a floating point value from a result set, returning zero if the value
in the result set was null.
|
static float |
getFloatValue(ResultSet rs,
String columnName,
float defaultValue)
Return a floating point value from the result set.
|
static String |
getStringValue(ResultSet rs,
String columnName)
Return the contents of a character column in a result set as a String object.
|
static String |
getStringValue(ResultSet rs,
String columnName,
String defaultValue)
Return a character value from a result set as a String object.
|
static String |
getStringValueEscaped(ResultSet rs,
String columnName)
Return the contents of a character column in a result set as a String object.
|
static String |
getStringValueEscaped(ResultSet rs,
String columnName,
String defaultValue)
Return a character value from a result set as a String object.
|
static void |
main(String[] args)
Test driver.
|
static void |
setChar(PreparedStatement stmt,
int position,
ResultSet rs,
String name)
Set a CHAR column in a prepared statement.
|
static void |
setChar(PreparedStatement stmt,
int position,
ResultSet rs,
String name,
boolean toUpperCase)
Set a CHAR column in a prepared statement.
|
static void |
setChar(PreparedStatement stmt,
int position,
String value)
Set a CHAR column in a prepared statement.
|
static void |
setChar(PreparedStatement stmt,
int position,
String value,
boolean toUpperCase)
Set a CHAR column in a prepared statement.
|
static void |
setFloat(PreparedStatement stmt,
int position,
Float value)
Set a FLOAT column in a prepared statement.
|
static void |
setFloat(PreparedStatement stmt,
int position,
ResultSet rs,
String name)
Set a FLOAT column in a prepared statement.
|
static void |
setInteger(PreparedStatement stmt,
int position,
Integer value)
Set a INTEGER column in a prepared statement.
|
static void |
setInteger(PreparedStatement stmt,
int position,
ResultSet rs,
Integer name)
Set a INTEGER column in a prepared statement.
|
static void |
setVarchar(PreparedStatement stmt,
int position,
ResultSet rs,
String name)
Set a VARCHAR column in a prepared statement.
|
static void |
setVarchar(PreparedStatement stmt,
int position,
ResultSet rs,
String name,
boolean toUpperCase)
Set a VARCHAR column in a prepared statement.
|
static void |
setVarchar(PreparedStatement stmt,
int position,
String value)
Set a VARCHAR column in a prepared statement.
|
static void |
setVarchar(PreparedStatement stmt,
int position,
String value,
boolean toUpperCase)
Set a VARCHAR column in a prepared statement.
|
static String |
showParameters(HttpServletRequest request)
Place information on the parameters in the body of the servlet.
|
static String |
valueWithDefault(String value,
String ifDefault)
Returns a default value if the examined value is null.
|
protected DatabaseProperties data
public ServletHelpers(DatabaseProperties dataValue)
public static String formatElapsedTime(long startTime)
By using this method, you avoid the possibility of the value for milliseconds displaying with over a dozen digits due to round-off error.
startTime
- Date (in milliseconds that was generated using
a previous java.util.Date object.Date
,
NumberFormat
public static String valueWithDefault(String value, String ifDefault)
Trying to run a number of String methods, such as equals or equalsIgnoreCase, result in exeptions being thrown if the object being examined has a value of null
value
- String value to be examinedifDefault
- Default value to be used if value is nullpublic static String doubleDoubleQuotes(String value)
value
- String to be processedpublic static String escapeDoubleQuotes(String value)
value
- String to be processedpublic static String getStringValue(ResultSet rs, String columnName, String defaultValue) throws SQLException
rs
- Result set to be usedcolumnName
- Name of column to be readdefaultValue
- Default value if column in result set has a value of nullSQLException
public static String getStringValueEscaped(ResultSet rs, String columnName, String defaultValue) throws SQLException
rs
- Result set to be readcolumnName
- Name of column to be readdefaultValue
- Default value to be used in value in database is nullSQLException
public static String getStringValue(ResultSet rs, String columnName) throws SQLException
rs
- Result set to be readcolumnName
- Name of column to be readSQLException
public static String getStringValueEscaped(ResultSet rs, String columnName) throws SQLException
This method escapes the character strings using the HTML character entity literals before returning the data to the calling program.
rs
- Result set to be readcolumnName
- Name of column to be readSQLException
public static float getFloatValue(ResultSet rs, String columnName, float defaultValue) throws SQLException
rs
- ResultSet object containing informationcolumnName
- Name of column in result setdefaultValue
- Value to be returned if value of column is nullSQLException
public static float getFloatValue(ResultSet rs, String columnName) throws SQLException
rs
- Result set from which data is to be takencolumnName
- Name of column in result setSQLException
public static void setChar(PreparedStatement stmt, int position, String value) throws SQLException
stmt
- Prepared statementposition
- Position in prepared statementvalue
- Value to be used for parameterSQLException
public static void setChar(PreparedStatement stmt, int position, String value, boolean toUpperCase) throws SQLException
stmt
- Prepared statementposition
- Position in prepared statementvalue
- Value to be used for parametertoUpperCase
- True means strings are converted to upper caseSQLException
public static void setChar(PreparedStatement stmt, int position, ResultSet rs, String name) throws SQLException
stmt
- Prepared statementposition
- Position in prepared statementrs
- Result set containing value to be used for parametername
- Name of column in result setSQLException
public static void setChar(PreparedStatement stmt, int position, ResultSet rs, String name, boolean toUpperCase) throws SQLException
stmt
- Prepared statementposition
- Position in prepared statementrs
- Result set containing value to be used for parametername
- Name of column in result settoUpperCase
- True means strings are converted to upper caseSQLException
public static void setVarchar(PreparedStatement stmt, int position, String value) throws SQLException
stmt
- Prepared statementposition
- Position in prepared statementvalue
- Value to be used for parameterSQLException
public static void setVarchar(PreparedStatement stmt, int position, String value, boolean toUpperCase) throws SQLException
stmt
- Prepared statementposition
- Position in prepared statementvalue
- Value to be used for parametertoUpperCase
- True means that strings are converted to upper caseSQLException
public static void setVarchar(PreparedStatement stmt, int position, ResultSet rs, String name) throws SQLException
stmt
- Prepared statementposition
- Position in prepared statementrs
- Result set containing value to be used for parametername
- Name of column in result setSQLException
public static void setVarchar(PreparedStatement stmt, int position, ResultSet rs, String name, boolean toUpperCase) throws SQLException
stmt
- Prepared statementposition
- Position in prepared statementrs
- Result set containing value to be used for parametername
- Name of column in result settoUpperCase
- True means that strings are to be converted to upper caseSQLException
public static void setFloat(PreparedStatement stmt, int position, Float value) throws SQLException
stmt
- Prepared statementposition
- Position in prepared statementvalue
- Value to be used for parameterSQLException
public static void setFloat(PreparedStatement stmt, int position, ResultSet rs, String name) throws SQLException
stmt
- Prepared statementposition
- Position in prepared statementrs
- Result set containing value to be used for parametername
- Name of column in result setSQLException
public static void setInteger(PreparedStatement stmt, int position, Integer value) throws SQLException
stmt
- Prepared statementposition
- Position in prepared statementvalue
- Value to be used for parameterSQLException
public static void setInteger(PreparedStatement stmt, int position, ResultSet rs, Integer name) throws SQLException
stmt
- Prepared statementposition
- Position in prepared statementrs
- Result set containing value to be used for parametername
- Name of column in result setSQLException
public static Date buildDate(String yearValue, String monthValue, String dayValue)
yearValue
- Year (4 digit)monthValue
- Number of Month (January = 1)dayValue
- Day of monthpublic static Date buildDate(int year, int month, int day)
year
- Year (4 digit)month
- Number of month (January = 1)day
- Day of monthpublic static String showParameters(HttpServletRequest request)
This is intended for debugging purposes.
request
- Request object