📄 jdbchelper.java.mod
字号:
{ i_columnIndex = column; Timestamp returnValue = i_resultSet.getTimestamp(column); i_columnIndex = 0; return returnValue; } /** * Calls the getDate() method on the ResultSet. * If the column has a null, this will return a null. * @param column a value of type 'String' * @return a value of type 'Date' * @exception SQLException if column is not found */ public Date getDate(String column) throws SQLException { i_columnName = column; Date returnValue = i_resultSet.getDate(column); i_columnName = EMPTY_STRING; return returnValue; } /** * Calls the getDate() method on the ResultSet. * If the column has a null, this will return a null. * @param column a value of type 'int' * @return a value of type 'Date' * @exception SQLException if column is not found */ public Date getDate(int column) throws SQLException { i_columnIndex = column; Date returnValue = i_resultSet.getDate(column); i_columnIndex = 0; return returnValue; } /** * Calls the getInt() method on the ResultSet and wraps the resulting int * in an Integer. If database has a null, null is returned. * @param column a value of type 'String' * @return a value of type 'Integer' * @exception SQLException if column is not found */ public Integer getInteger(String column) throws SQLException { i_columnName = column; Integer returnValue = new Integer(i_resultSet.getInt(column)); i_columnName = EMPTY_STRING; if (i_resultSet.wasNull()) { returnValue = null; } return returnValue; } /** * Calls the getInt() method on the ResultSet and wraps the resulting int * in an Integer. If database has a null, null is returned. * @param column a value of type 'int' * @return a value of type 'Integer' * @exception SQLException if column is not found */ public Integer getInteger(int column) throws SQLException { i_columnIndex = column; Integer returnValue = new Integer(i_resultSet.getInt(column)); i_columnIndex = 0; if (i_resultSet.wasNull()) { returnValue = null; } return returnValue; } /** * Calls the getInt() method on the ResultSet. * If the column has a null, this will return a zero. * @param column a value of type 'String' * @return a value of type 'int' * @exception SQLException if column is not found */ public int getint(String column) throws SQLException { i_columnName = column; int returnValue = i_resultSet.getInt(column); i_columnName = EMPTY_STRING; return returnValue; } /** * Calls the getInt() method on the ResultSet. * If the column has a null, this will return a zero. * @param column a value of type 'int' * @return a value of type 'int' * @exception SQLException if column is not found */ public int getint(int column) throws SQLException { i_columnIndex = column; int returnValue = i_resultSet.getInt(column); i_columnIndex = 0; return returnValue; } /** * Calls the getLong() method on the ResultSet. * If the column has a null, this will return a zero. * @param column a value of type 'String' * @return a value of type 'long' * @exception SQLException if column is not found */ public long getlong(String column) throws SQLException { i_columnName = column; long returnValue = i_resultSet.getLong(column); i_columnName = EMPTY_STRING; return returnValue; } /** * Calls the getLong() method on the ResultSet. * If the column has a null, this will return a zero. * @param column a value of type 'int' * @return a value of type 'long' * @exception SQLException if column is not found */ public long getlong(int column) throws SQLException { i_columnIndex = column; long returnValue = i_resultSet.getLong(column); i_columnIndex = 0; return returnValue; } /** * Calls the getFloat() method on the ResultSet and wraps the resulting * float in a Float. If database has a null, null is returned. * @param column a value of type 'String' * @return a value of type 'Float' * @exception SQLException if column is not found */ public Float getFloat(String column) throws SQLException { i_columnName = column; Float returnValue = new Float(i_resultSet.getFloat(column)); i_columnName = EMPTY_STRING; if (i_resultSet.wasNull()) { returnValue = null; } return returnValue; } /** * Calls the getFloat() method on the ResultSet and wraps the resulting * float in a Float. If database has a null, null is returned. * @param column a value of type 'int' * @return a value of type 'Float' * @exception SQLException if column is not found */ public Float getFloat(int column) throws SQLException { i_columnIndex = column; Float returnValue = new Float(i_resultSet.getFloat(column)); i_columnIndex = 0; if (i_resultSet.wasNull()) { returnValue = null; } return returnValue; } /** * Calls the getFloat() method on the ResultSet. * If the column has a null, this will return a zero. * @param column a value of type 'String' * @return a value of type 'float' * @exception SQLException if column is not found */ public float getfloat(String column) throws SQLException { i_columnName = column; float returnValue = i_resultSet.getFloat(column); i_columnName = EMPTY_STRING; return returnValue; } /** * Calls the getFloat() method on the ResultSet. * If the column has a null, this will return a zero. * @param column a value of type 'int' * @return a value of type 'float' * @exception SQLException if column is not found */ public float getfloat(int column) throws SQLException { i_columnIndex = column; float returnValue = i_resultSet.getFloat(column); i_columnIndex = 0; return returnValue; } /** * Calls the getDouble() method on the ResultSet and wraps the resulting * double in a Double. If database has a null, null is returned. * @param column a value of type 'String' * @return a value of type 'Double' * @exception SQLException if column is not found */ public Double getDouble(String column) throws SQLException { i_columnName = column; Double returnValue = new Double(i_resultSet.getDouble(column)); i_columnName = EMPTY_STRING; if (i_resultSet.wasNull()) { returnValue = null; } return returnValue; } /** * Calls the getDouble() method on the ResultSet and wraps the resulting * double in a Double. If database has a null, null is returned. * @param column a value of type 'int' * @return a value of type 'Double' * @exception SQLException if column is not found */ public Double getDouble(int column) throws SQLException { i_columnIndex = column; Double returnValue = new Double(i_resultSet.getDouble(column)); i_columnIndex = 0; if (i_resultSet.wasNull()) { returnValue = null; } return returnValue; } /** * Calls the getDouble() method on the ResultSet. * If the column has a null, this will return a zero. * @param column a value of type 'String' * @return a value of type 'double' * @exception SQLException if column is not found */ public double getdouble(String column) throws SQLException { i_columnName = column; double returnValue = i_resultSet.getDouble(column); i_columnName = EMPTY_STRING; return returnValue; } /** * Calls the getDouble() method on the ResultSet. * If the column has a null, this will return a zero. * @param column a value of type 'int' * @return a value of type 'double' * @exception SQLException if column is not found */ public double getdouble(int column) throws SQLException { i_columnIndex = column; double returnValue = i_resultSet.getDouble(column); i_columnIndex = 0; return returnValue; } /** * Calls the getBigDecimal() method on the ResultSet. * If the column has a null, this will return null. * @param column a value of type String * @return a value of type BigDecimal * @exception SQLException if column is not found */ public BigDecimal getBigDecimal(String column) throws SQLException { i_columnName = column; // WORKAROUND **** // Weblogic hasn't implemented ResultSet.getBigDecimal yet. // For now get it as a String and turn into a BigDecimal. String resultString = i_resultSet.getString(column); BigDecimal returnValue = new BigDecimal(resultString); i_columnName = EMPTY_STRING; return returnValue; } /** * Calls the getBigDecimal() method on the ResultSet. * If the column has a null, this will return null. * @param column a value of type 'int' * @return a value of type 'BigDecimal' * @exception SQLException if column is not found */ public BigDecimal getBigDecimal(int column) throws SQLException { i_columnIndex = column; // WORKAROUND **** // Weblogic hasn't implemented ResultSet.getBigDecimal yet. // For now get it as a String and turn into a BigDecimal. String resultString = i_resultSet.getString(column); BigDecimal returnValue = new BigDecimal(resultString); i_columnIndex = 0; return returnValue; } /** * Calls the getBytes() method on the ResultSet. * If the column has a null, this will return a null. * @param column a value of type 'int' * @return a value of type 'byte[]' * @exception SQLException if column is not found */ public byte[] getBytes(int column) throws SQLException { i_columnIndex = column; byte[] returnValue = i_resultSet.getBytes(column); i_columnIndex = 0; return returnValue; } /** * Calls the getBytes() method on the ResultSet. * If the column has a null, this will return a null. * @param column a value of type 'String' * @return a value of type 'byte[]' * @exception SQLException if column is not found */ public byte[] getBytes(String column) throws SQLException { i_columnName = column; byte[] returnValue = i_resultSet.getBytes(column); i_columnName = EMPTY_STRING; return returnValue; } /* ========== Convenience Helper Methods ========== */ /** * Formats a String for use as a String in a DB query * where a single quote is the delimiter. * * @param p_val the String to format * @return String with quotes escaped, and enclosing. * @see #delimitString */ public static String delimitSingleQuote(String p_val) { return JDBCHelper.delimitString(p_val, SINGLE_QUOTE); } /** * Formats a String for use as a String in a DB query * where a double quote is the delimiter. * * @param p_val the String to format * @return String with quotes escaped, and enclosing. * @see #delimitString */ public static String delimitDoubleQuote(String p_val) { return JDBCHelper.delimitString(p_val, DOUBLE_QUOTE); } /** * STATIC CLASS METHOD: * Formats a String for use as a String in a DB query * where the delimiter is as provided. * * @param p_val the String to format * @param p_delimiter the delimiter for formatting * @return String with quotes escaped, and enclosing. */ public static String delimitString(String p_val, String p_delimiter) { String result = null; // replace occurrances of the delimiter with "double delimiters" // to "escape" the delimiter character within the string. result = JDBCHelper.replace(p_val, p_delimiter, (p_delimiter + p_delimiter)); // pre&post pend the delimiter result = p_delimiter + result + p_delimiter; return result; } /** * Replace occurrences of oldString with newString within the content text. * @param content The text String that will be acted upon (strings * replaced). * @param oldString The string that will be replaced. * @param newString The string that will replace oldString. * @return returns the content string with the replaced values, as a * String, or original content if bad parms. */ public static String replace(String content, String oldString, String newString) { // if any parms null or too small, no point in doing anything...return // content if ((content == null) || (oldString == null) || (oldString.length() < 1) || (newString == null)) { return content; } // if content too small to contain oldString, no point in doing // anything...return content if (content.length() < oldString.length()) { return content; } // Perform String replacement String newContent = content; int foundIndex = content.indexOf(oldString); // Recurse through the string, replacing ALL occurrences recurse rather // than loop to allow a replace that includes itself (eg "'" with "''" - // SQL escaping) if (foundIndex != -1) { try { newContent = content.substring(0, foundIndex) + newString + replace( content.substring(foundIndex + oldString.length(), content.length()), oldString, newString); } catch (StringIndexOutOfBoundsException e) {} } return newContent; } // replace(...) /** * For a given List, this method creates a comma-separated string list and * surrounds it with parenthesis. It is suitable for use in any SQL clauses * where that formatting is required.<br> * e.g. WHERE IN (foo,bar,blah) * e.g. VALUES (tom,dick,harry)<br> * * This calls the String.valueOf() method on each List element to produce the values. * * @param objects a value of type 'List' * @return a value of type 'String' */ public static String getSQLList(List objects) { if (objects == null || objects.size() < 1) { return IN_EMPTY; } // Create a comma delimited, paren enclosed string of all the objects in // the List. #toString() on AbstractCollection does this but uses [] instead // of (), so we have to replace it. Elements are converted to strings as by // String.valueOf(Object). // So if Your list contains: // // 1234 // 5678 // 9012 // // ... the resulting String will be: // (1234, 5678, 9012) return objects.toString().replace(LIST_BEGIN, IN_BEGIN).replace(LIST_END, IN_END); } } // JDBCHelper
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -