📄 resultset_base.java
字号:
/**
* 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; if the value is SQL NULL, the result is false
* @exception SQLException if a database-access error occurs.
*/
public boolean getBoolean(int columnIndex) throws SQLException
{
Object obj = getObject(columnIndex);
boolean result;
if (obj == null)
{
result = false;
}
else
{
switch(getMetaData().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?
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...
if (! (obj instanceof String))
{
// Must be out of sync with the implementation of
// Tds.getRow() for this to happen.
throw new SQLException("Internal error");
}
char ch = (((String)obj) + "n").charAt(0);
result = (ch=='Y')||(ch=='y')||(ch=='t')||(ch=='T');
break;
}
default:
{
throw new SQLException("Can't convert column " + columnIndex
+ " from "
+ obj.getClass().getName()
+ " to boolean");
}
}
}
return result;
} // getBoolean()
/**
* Get the value of a column in the current row as a Java boolean.
*
* @param columnName is the SQL name of the column
* @return the column value; if the value is SQL NULL, the result is false
* @exception SQLException if a database-access error occurs.
*/
public boolean getBoolean(String columnName) throws SQLException
{
return getBoolean(findColumn(columnName));
} // getBoolean()
/**
* 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; if the value is SQL NULL, the result is 0
* @exception SQLException if a database-access error occurs.
*/
public byte getByte(int columnIndex) throws SQLException
{
return (byte) getLong(columnIndex);
}
/**
* Get the value of a column in the current row as a Java byte.
*
* @param columnName is the SQL name of the column
* @return the column value; if the value is SQL NULL, the result is 0
* @exception SQLException if a database-access error occurs.
*/
public byte getByte(String columnName) throws SQLException
{
return getByte(findColumn(columnName));
}
/**
* Get the value of a column in the current row as a Java byte array.
* The bytes represent the raw values returned by the driver.
*
* @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 SQLException if a database-access error occurs.
*/
public byte[] getBytes(int columnIndex) throws SQLException
{
byte result[];
try
{
Object tmp = currentRow.getElementAt(columnIndex);
lastGetWasNull = false;
if (tmp == null)
{
lastGetWasNull = true;
result = null;
}
else if (tmp instanceof byte[])
{
result = (byte[])tmp;
}
else if (tmp instanceof String)
{
result = tds.getEncoder().getBytes((String)tmp);
}
else
{
throw new SQLException("Can't convert column " + columnIndex
+ " from "
+ tmp.getClass().getName()
+ " to byte[]");
}
}
catch (TdsException e)
{
e.printStackTrace();
throw new SQLException(e.getMessage());
}
return result;
}
/**
* Get the value of a column in the current row as a Java byte array.
* The bytes represent the raw values returned by the driver.
*
* @param columnName is the SQL name of the column
* @return the column value; if the value is SQL NULL, the result is null
* @exception SQLException if a database-access error occurs.
*/
public byte[] getBytes(String columnName) throws SQLException
{
return getBytes(findColumn(columnName));
}
/**
* Get the name of the SQL cursor used by this ResultSet.
*
* <P>In SQL, a result table is retrieved through a cursor that is
* named. The current row of a result can be updated or deleted
* using a positioned update/delete statement that references the
* cursor name.
*
* <P>JDBC supports this SQL feature by providing the name of the
* SQL cursor used by a ResultSet. The current row of a ResultSet
* is also the current row of this SQL cursor.
*
* <P><B>Note:</B> If positioned update is not supported a
* SQLException is thrown
*
* @return the ResultSet's SQL cursor name
* @exception SQLException if a database-access error occurs.
*/
public String getCursorName() throws SQLException
{
throw new SQLException("Not implemented (getCursorName)");
}
/**
* Get the value of a column in the current row as a java.sql.Date object.
*
* @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 SQLException if a database-access error occurs.
*/
public java.sql.Date getDate(int columnIndex) throws SQLException
{
java.sql.Date result = null;
java.sql.Timestamp tmp = getTimestamp(columnIndex);
if (tmp != null)
{
result = new java.sql.Date(tmp.getTime());
}
return result;
}
/**
* Get the value of a column in the current row as a java.sql.Date object.
*
* @param columnName is the SQL name of the column
* @return the column value; if the value is SQL NULL, the result is null
* @exception SQLException if a database-access error occurs.
*/
public java.sql.Date getDate(String columnName) throws SQLException
{
return getDate(findColumn(columnName));
}
/**
* Get the value of a column in the current row as a Java double.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @return the column value; if the value is SQL NULL, the result is 0
* @exception SQLException if a database-access error occurs.
*/
public double getDouble(int columnIndex) throws SQLException
{
double result;
Object obj = getObject(columnIndex);
if (obj == null)
{
result = 0.0;
}
else
{
try
{
switch(getMetaData().getColumnType(columnIndex))
{
case java.sql.Types.TINYINT:
case java.sql.Types.SMALLINT:
case java.sql.Types.INTEGER:
{
result = ((Number)obj).doubleValue();
break;
}
case java.sql.Types.BIGINT:
{
result = ((Number)obj).doubleValue();
break;
}
case java.sql.Types.REAL:
{
result = ((Float)obj).doubleValue();
break;
}
case java.sql.Types.FLOAT:
case java.sql.Types.DOUBLE:
{
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.DECIMAL:
case java.sql.Types.NUMERIC:
{
result = ((BigDecimal)obj).doubleValue();
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(getMetaData().getColumnType(columnIndex))
+ " to an Dboule");
}
}
}
catch(ClassCastException e)
{
throw new SQLException("Couldn't convert column " + columnIndex
+ " to an long. "
+ e.getMessage());
}
}
return result;
} /* getDouble() */
/**
* Get the value of a column in the current row as a Java double.
*
* @param columnName is the SQL name of the column
* @return the column value; if the value is SQL NULL, the result is 0
* @exception SQLException if a database-access error occurs.
*/
public double getDouble(String columnName) throws SQLException
{
return getDouble(findColumn(columnName));
}
/**
* Get the value of a column in the current row as a Java float.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @return the column value; if the value is SQL NULL, the result is 0
* @exception SQLException if a database-access error occurs.
*/
public float getFloat(int columnIndex) throws SQLException
{
return (float)getDouble(columnIndex);
}
/**
* Get the value of a column in the current row as a Java float.
*
* @param columnName is the SQL name of the column
* @return the column value; if the value is SQL NULL, the result is 0
* @exception SQLException if a database-access error occurs.
*/
public float getFloat(String columnName) throws SQLException
{
return getFloat(findColumn(columnName));
}
/**
* Get the value of a column in the current row as a Java int.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @return the column value; if the value is SQL NULL, the result is 0
* @exception SQLException if a database-access error occurs.
*/
public int getInt(int columnIndex) throws SQLException
{
return (int) getLong(columnIndex);
}
/**
* Get the value of a column in the current row as a Java int.
*
* @param columnName is the SQL name of the column
* @return the column value; if the value is SQL NULL, the result is 0
* @exception SQLException if a database-access error occurs.
*/
public int getInt(String columnName) throws SQLException
{
return getInt(findColumn(columnName));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -