📄 resultset.java
字号:
* Get the value of a column in the current row as a java.math.BigDecimal * object * * @param columnIndex the first column is 1, the second is 2... * @param scale the number of digits to the right of the decimal * * @return the column value; if the value is SQL NULL, null * * @exception java.sql.SQLException if a database access error occurs */ public BigDecimal getBigDecimal(int columnIndex, int scale) throws java.sql.SQLException { String stringVal = getString(columnIndex); BigDecimal val; if (stringVal != null) { if (stringVal.length() == 0) { val = new BigDecimal(0); return val.setScale(scale); } try { val = new BigDecimal(stringVal); } catch (NumberFormatException ex) { throw new java.sql.SQLException("Bad format for BigDecimal '" + stringVal + "' in column " + columnIndex + "(" + fields[columnIndex - 1] + ").", SQLError.SQL_STATE_ILLEGAL_ARGUMENT); } try { return val.setScale(scale); } catch (ArithmeticException ex) { throw new java.sql.SQLException("Bad format for BigDecimal '" + stringVal + "' in column " + columnIndex + "(" + fields[columnIndex - 1] + ").", SQLError.SQL_STATE_ILLEGAL_ARGUMENT); } } return null; } /** * DOCUMENT ME! * * @param columnName DOCUMENT ME! * @param scale DOCUMENT ME! * * @return DOCUMENT ME! * * @throws java.sql.SQLException DOCUMENT ME! */ public BigDecimal getBigDecimal(String columnName, int scale) throws java.sql.SQLException { return getBigDecimal(findColumn(columnName), scale); } /** * JDBC 2.0 Get the value of a column in the current row as a * java.math.BigDecimal object. * * @param columnIndex the first column is 1, the second is 2, ... * * @return the column value (full precision); if the value is SQL NULL, the * result is null * * @exception SQLException if a database-access error occurs. * @throws java.sql.SQLException DOCUMENT ME! */ public BigDecimal getBigDecimal(int columnIndex) throws SQLException { String stringVal = getString(columnIndex); BigDecimal val; if (stringVal != null) { if (stringVal.length() == 0) { val = new BigDecimal(0); return val; } try { val = new BigDecimal(stringVal); return val; } catch (NumberFormatException ex) { throw new java.sql.SQLException("Bad format for BigDecimal '" + stringVal + "' in column " + columnIndex + "(" + fields[columnIndex - 1] + ").", SQLError.SQL_STATE_ILLEGAL_ARGUMENT); } } return null; } /** * JDBC 2.0 Get the value of a column in the current row as a * java.math.BigDecimal object. * * @param columnName the name of the column to retrieve the value from * * @return the BigDecimal value in the column * * @throws SQLException if an error occurs */ public BigDecimal getBigDecimal(String columnName) throws SQLException { return getBigDecimal(findColumn(columnName)); } /** * A column value can also be retrieved as a binary strea. This method is * suitable for retrieving LONGVARBINARY values. * * @param columnIndex the first column is 1, the second is 2... * * @return a Java InputStream that delivers the database column value as a * stream of bytes. If the value is SQL NULL, then the result is * null * * @exception java.sql.SQLException if a database access error occurs * * @see getAsciiStream * @see getUnicodeStream */ public InputStream getBinaryStream(int columnIndex) throws java.sql.SQLException { checkRowPos(); byte[] b = getBytes(columnIndex); if (b != null) { return new ByteArrayInputStream(b); } return null; } /** * DOCUMENT ME! * * @param columnName DOCUMENT ME! * * @return DOCUMENT ME! * * @throws java.sql.SQLException DOCUMENT ME! */ public InputStream getBinaryStream(String columnName) throws java.sql.SQLException { return getBinaryStream(findColumn(columnName)); } /** * JDBC 2.0 Get a BLOB column. * * @param columnIndex the first column is 1, the second is 2, ... * * @return an object representing a BLOB * * @throws SQLException if an error occurs. * @throws java.sql.SQLException DOCUMENT ME! */ public java.sql.Blob getBlob(int columnIndex) throws SQLException { checkRowPos(); if ((columnIndex < 1) || (columnIndex > fields.length)) { throw new java.sql.SQLException("Column Index out of range ( " + columnIndex + " > " + fields.length + ").", SQLError.SQL_STATE_INVALID_COLUMN_NUMBER); } try { if (thisRow[columnIndex - 1] == null) { wasNullFlag = true; } else { wasNullFlag = false; } } catch (NullPointerException ex) { wasNullFlag = true; } if (wasNullFlag) { return null; } return new Blob(thisRow[columnIndex - 1]); } /** * JDBC 2.0 Get a BLOB column. * * @param colName the column name * * @return an object representing a BLOB * * @throws SQLException if an error occurs. */ public java.sql.Blob getBlob(String colName) throws SQLException { return getBlob(findColumn(colName)); } /** * Get the value of a column in the current row as a Java boolean * * @param columnIndex the first column is 1, the second is 2... * * @return the column value, false for SQL NULL * * @exception java.sql.SQLException if a database access error occurs */ public boolean getBoolean(int columnIndex) throws java.sql.SQLException { String stringVal = getString(columnIndex); if ((stringVal != null) && (stringVal.length() > 0)) { int c = Character.toLowerCase(stringVal.charAt(0)); return ((c == 't') || (c == 'y') || (c == '1') || stringVal.equals("-1")); } return false; } /** * DOCUMENT ME! * * @param columnName DOCUMENT ME! * * @return DOCUMENT ME! * * @throws java.sql.SQLException DOCUMENT ME! */ public boolean getBoolean(String columnName) throws java.sql.SQLException { return getBoolean(findColumn(columnName)); } /** * Get the value of a column in the current row as a Java byte. * * @param columnIndex the first column is 1, the second is 2,... * * @return the column value; 0 if SQL NULL * * @exception java.sql.SQLException if a database access error occurs * @throws SQLException DOCUMENT ME! */ public byte getByte(int columnIndex) throws java.sql.SQLException { String stringVal = getString(columnIndex); if (this.wasNullFlag || stringVal == null) { return 0; } Field field = fields[columnIndex - 1]; switch (field.getMysqlType()) { case MysqlDefs.FIELD_TYPE_DECIMAL: case MysqlDefs.FIELD_TYPE_TINY: case MysqlDefs.FIELD_TYPE_SHORT: case MysqlDefs.FIELD_TYPE_LONG: case MysqlDefs.FIELD_TYPE_FLOAT: case MysqlDefs.FIELD_TYPE_DOUBLE: case MysqlDefs.FIELD_TYPE_LONGLONG: case MysqlDefs.FIELD_TYPE_INT24: try { int decimalIndex = stringVal.indexOf("."); // Strip off the decimals if (decimalIndex != -1) { stringVal = stringVal.substring(0, decimalIndex); } return Byte.parseByte(stringVal); } catch (NumberFormatException NFE) { throw new SQLException("Value '" + getString(columnIndex) + "' is out of range [-127,127]", SQLError.SQL_STATE_ILLEGAL_ARGUMENT); } default: try { int decimalIndex = stringVal.indexOf("."); // Strip off the decimals if (decimalIndex != -1) { stringVal = stringVal.substring(0, decimalIndex); } return Byte.parseByte(stringVal); } catch (NumberFormatException NFE) { throw new SQLException("Value '" + getString(columnIndex) + "' is out of range [-127,127]", SQLError.SQL_STATE_ILLEGAL_ARGUMENT); } } } /** * DOCUMENT ME! * * @param columnName DOCUMENT ME! * * @return DOCUMENT ME! * * @throws java.sql.SQLException DOCUMENT ME! */ public byte getByte(String columnName) throws java.sql.SQLException { return getByte(findColumn(columnName)); } /** * Get the value of a column in the current row as a Java byte array. * * <p> * <b>Be warned</b> If the blob is huge, then you may run out of memory. * </p> * * @param columnIndex the first column is 1, the second is 2, ... * * @return the column value; if the value is SQL NULL, the result is null * * @exception java.sql.SQLException if a database access error occurs */ public byte[] getBytes(int columnIndex) throws java.sql.SQLException { checkRowPos(); try { if (thisRow[columnIndex - 1] == null) { wasNullFlag = true; } else { wasNullFlag = false; } } catch (NullPointerException E) { wasNullFlag = true; } catch (ArrayIndexOutOfBoundsException aioobEx) { throw new java.sql.SQLException("Column Index out of range ( " + columnIndex + " > " + fields.length + ").", SQLError.SQL_STATE_INVALID_COLUMN_NUMBER); } if (wasNullFlag) { return null; } else { return thisRow[columnIndex - 1]; } } /** * DOCUMENT ME! * * @param columnName DOCUMENT ME! * * @return DOCUMENT ME! * * @throws java.sql.SQLException DOCUMENT ME! */ public byte[] getBytes(String columnName) throws java.sql.SQLException { return getBytes(findColumn(columnName)); } //--------------------------JDBC 2.0----------------------------------- //--------------------------------------------------------------------- // Getter's and Setter's //--------------------------------------------------------------------- /** * JDBC 2.0 * * <p> * Get the value of a column in the current row as a java.io.Reader. * </p> * * @param columnIndex the column to get the value from * * @return the value in the column as a java.io.Reader. * * @throws SQLException if an error occurs */ public java.io.Reader getCharacterStream(int columnIndex) throws SQLException { String stringVal = getString(columnIndex); if (stringVal != null) { return new StringReader(stringVal); } else { return null; } } /** * JDBC 2.0 * * <p> * Get the value of a column in the current row as a java.io.Reader. * </p> * * @param columnName the column name to retrieve the value from * * @return the value as a java.io.Reader * * @throws SQLException if an error occurs */ public java.io.Reader getCharacterStream(String columnName) throws SQLException { return getCharacterStream(findColumn(columnName)); } /** * JDBC 2.0 Get a CLOB column. *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -