📄 packetrowresult.java
字号:
public double getDouble( int columnIndex ) throws SQLException
{
double result;
Object obj = getObject( columnIndex );
if ( obj == null ) {
result = 0.0;
}
else {
try {
switch ( getColumnType( columnIndex ) ) {
case java.sql.Types.TINYINT:
case java.sql.Types.SMALLINT:
case java.sql.Types.INTEGER:
case java.sql.Types.BIGINT:
case java.sql.Types.REAL:
case java.sql.Types.FLOAT:
case java.sql.Types.DOUBLE:
case java.sql.Types.DECIMAL:
case java.sql.Types.NUMERIC:
{
result = ((Number)obj).doubleValue();
break;
}
case java.sql.Types.CHAR:
case java.sql.Types.VARCHAR:
case java.sql.Types.LONGVARCHAR:
{
try {
Double d = new Double( ( String ) obj );
result = d.doubleValue();
}
catch ( NumberFormatException e ) {
throw new SQLException( e.getMessage() );
}
break;
}
case java.sql.Types.BIT:
{
// XXX according to JDBC spec we need to handle these
// for now just fall through
}
default:
{
throw new SQLException( "Internal error. "
+ "Don't know how to convert from "
+ "java.sql.Types." +
TdsUtil.javaSqlTypeToString( getColumnType( columnIndex ) )
+ " to an Dboule" );
}
}
}
catch ( ClassCastException e ) {
throw new SQLException( "Couldn't convert column " + columnIndex
+ " to an long. "
+ e.getMessage() );
}
}
return result;
}
public long getLong( int columnIndex ) throws SQLException
{
long result = 0;
Object obj = getObject( columnIndex );
if ( obj == null ) {
result = 0;
}
else {
try {
switch ( getColumnType( columnIndex ) ) {
case java.sql.Types.TINYINT:
case java.sql.Types.SMALLINT:
case java.sql.Types.INTEGER:
case java.sql.Types.BIGINT:
case java.sql.Types.REAL:
case java.sql.Types.FLOAT:
case java.sql.Types.DOUBLE:
{
result = ((Number)obj).longValue();
break;
}
case java.sql.Types.CHAR:
case java.sql.Types.VARCHAR:
case java.sql.Types.LONGVARCHAR:
{
try {
Long i = new Long(obj.toString().trim());
result = i.longValue();
}
catch ( NumberFormatException e ) {
throw new SQLException("NumberFormatException: ["+e.getMessage()+"]");
}
break;
}
case java.sql.Types.NUMERIC:
{
result = ( ( Number ) obj ).longValue();
break;
}
case java.sql.Types.DECIMAL:
{
result = ( ( Number ) obj ).longValue();
break;
}
case java.sql.Types.BIT:
{
result = ((Boolean)obj).booleanValue() ? 1 : 0;
break;
}
default:
{
throw new SQLException( "Internal error. "
+ "Don't know how to convert from "
+ "java.sql.Types " +
TdsUtil.javaSqlTypeToString( getColumnType( columnIndex ) )
+ " to an long" );
}
}
}
catch ( ClassCastException e ) {
throw new SQLException( "Couldn't convert column " + columnIndex
+ " to an long. "
+ e.getMessage() );
}
}
return result;
}
public java.sql.Timestamp getTimestamp( int columnIndex ) throws SQLException
{
Timestamp result;
try {
Object tmp = getElementAt( columnIndex );
wasNull = false;
if ( tmp == null ) {
wasNull = true;
result = null;
}
else if ( tmp instanceof Timestamp ) {
result = ( Timestamp ) tmp;
}
else {
throw new SQLException( "Can't convert column " + columnIndex
+ " from "
+ tmp.getClass().getName()
+ " to Timestamp" );
}
}
catch ( TdsException e ) {
throw new SQLException( e.getMessage() );
}
return result;
}
public BigDecimal getBigDecimal( int columnIndex )
throws SQLException
{
Object tmp = getObject( columnIndex );
if ( tmp == null ) {
return null;
}
BigDecimal result = null;
if ( tmp instanceof java.lang.Double ) {
result = new BigDecimal( ( ( Double ) tmp ).doubleValue() );
}
else if ( tmp instanceof java.lang.Float ) {
result = new BigDecimal( ( ( Float ) tmp ).doubleValue() );
}
else if ( tmp instanceof BigDecimal ) {
result = ( BigDecimal ) tmp;
}
else if ( tmp instanceof java.lang.Number ) {
// This handles Byte, Short, Integer, and Long
result = BigDecimal.valueOf( ( ( Number ) tmp ).longValue() );
}
else if ( tmp instanceof java.lang.String ) {
try {
result = new BigDecimal( ( String ) tmp );
}
catch ( NumberFormatException e ) {
throw new SQLException( e.getMessage() );
}
}
return result;
}
public BigDecimal getBigDecimal( int columnIndex, int scale )
throws SQLException
{
BigDecimal result = getBigDecimal( columnIndex );
if ( result == null ) {
return null;
}
return result.setScale( scale );
}
public boolean getBoolean( int columnIndex ) throws SQLException
{
Object obj = getObject( columnIndex );
boolean result;
if ( obj == null ) {
result = false;
}
else {
switch ( getColumnType( columnIndex ) ) {
case java.sql.Types.TINYINT:
case java.sql.Types.SMALLINT:
case java.sql.Types.INTEGER:
case java.sql.Types.BIGINT:
case java.sql.Types.REAL:
case java.sql.Types.FLOAT:
case java.sql.Types.DOUBLE:
case java.sql.Types.DECIMAL:
case java.sql.Types.NUMERIC:
{
if ( !( obj instanceof java.lang.Number ) ) {
// Must be out of sync with the implementation of
// Tds.getRow() for this to happen.
throw new SQLException( "Internal error" );
}
// Would somebody like to tell what a true/false has
// to do with a double?
// SAfe It looks like it has to work just like with BIT columns ('0' or 'false' for false and '1' or
// 'true' for true).
result = ( ( java.lang.Number ) obj ).intValue() != 0;
break;
}
case java.sql.Types.BIT:
{
if ( !( obj instanceof Boolean ) ) {
// Must be out of sync with the implementation of
// Tds.getRow() for this to happen.
throw new SQLException( "Internal error" );
}
result = ( ( Boolean ) obj ).booleanValue();
break;
}
case java.sql.Types.CHAR:
case java.sql.Types.VARCHAR:
case java.sql.Types.LONGVARCHAR:
{
// Okay, I'm really confused as to what you mean
// by a character string being true or false. What
// is the boolean value for "Let the wookie win"?
// But since the spec says I have to convert from
// character to boolean data...
// SAfe It looks like it has to work just like with BIT columns ('0' or 'false' for false and '1' or
// 'true' for true).
if ( !( obj instanceof String ) ) {
// Must be out of sync with the implementation of
// Tds.getRow() for this to happen.
throw new SQLException( "Internal error" );
}
String v = obj.toString().trim();
if( v.equalsIgnoreCase("0") || v.equalsIgnoreCase("false") )
{
result = false;
break;
}
else if( v.equalsIgnoreCase("1") || v.equalsIgnoreCase("true") )
{
result = true;
break;
}
// SAfe Otherwise fall-through to the "default:" label and throw an exception.
}
default:
{
throw new SQLException( "Can't convert column " + columnIndex
+ " from "
+ obj.getClass().getName()
+ " to boolean" );
}
}
}
return result;
}
// getBoolean()
public boolean wasNull()
{
return wasNull;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -