⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jdbchelper.java.robmoore.done

📁 把java对象映射成数据库表中的一条记录
💻 DONE
📖 第 1 页 / 共 3 页
字号:
    {
    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 = "";
    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 getLong() method on the ResultSet and wraps the resulting
   * long in a Long.  If database has a null, null is returned.
   * @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 = new Long(i_resultSet.getLong(column));
    i_columnName = "";
    if (i_resultSet.wasNull())
        {
        returnValue = null;
        }
    return returnValue;
    }


  /**
   * Calls the getLong() method on the ResultSet and wraps the resulting
   * long in a Long.  If database has a null, null is returned.
   * @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 = new Long(i_resultSet.getLong(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 = "";
    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 = "";
    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 = "";
    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 = "";
    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 = "";
    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 = "";
    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);
    if (resultString == null)
        {
        return (BigDecimal) null;
        }
    BigDecimal returnValue = new BigDecimal(resultString);
    i_columnName = "";
    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);
    if (resultString == null)
        {
        return (BigDecimal) null;
        }
    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 = "";
    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 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 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)
            {
            Category.getInstance("JDBCHelper").error(
                "Exception occured in JDBCHelper.replace()... Ignoring.", e);
            }
        }
    return newContent;
    } // replace(...)


  } // JDBCHelper


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -