oracle.jdbc.internal.ObjectData
, OracleData
, ORAData
public class ANYDATA extends Object implements ORAData, OracleData
You can construct an ANYDATA instance from a Datum instance using ANYDATA.convertDatum(Datum)
. The following example shows how to construct an ANYDATA instance that encapsulates a NUMBER:
NUMBER num = new NUMBER(12345); ANYDATA anydt = ANYDATA.convertDatum(num);The
ANYDATA.convertDatum(Datum)
method is the java equivalent of the PLSQL ConvertXXX
procedures. In the previous example we could also have used PLSQL to construct the ANYDATA instance and retrieve it in Java:
// conn being a JDBC connection Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("select ANYDATA.ConvertNUMBER(12345) from dual"); ANYDATA anydt = null; if(rs.next()) anydt = (ANYDATA)rs.getObject(1);
The public method getTypeDescriptor()
returns an instance of TypeDescriptor
which provides a description of the type. To retrieve the actual data, use accessDatum()
which returns an instance of Datum
. To know what to cast it to, use the type description. For example:
Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("select anydatacol from foo"); while(rs.next()) { ANYDATA anydt = (ANYDATA)rs.getObject(1); System.out.println(anydt.stringValue()); TypeDescriptor typedesc = anydt.getTypeDescriptor(); Datum embeddedDatum = anydt.accessDatum(); if(typedesc.getTypeCode() == TypeDescriptor.TYPECODE_DATE) { // the embedded object is a DATE: DATE datedatum = (DATE)embeddedDatum; // etc. } else if(typedesc.getTypeCode() == TypeDescriptor.TYPECODE_NUMBER) { // the embedded object is a NUMBER NUMBER numberdatum = (NUMBER)embeddedDatum; // etc. } }
Modifier and Type | Method | Description |
---|---|---|
Datum |
accessDatum() |
Returns the embedded object.
|
static ANYDATA |
convertDatum(Datum datum) |
Constructs an ANYDATA instance from any instance of
Datum . |
protected oracle.jdbc.internal.OracleConnection |
getConnectionDuringExceptionHandling() |
|
byte[] |
getData() |
Returns the linearized form of the embedded object value.
|
TypeDescriptor |
getTypeDescriptor() |
Returns the type description of this ANYDATA instance.
|
boolean |
isNull() |
Returns true if the data part of this ANYDATA instance is null and false otherwise.
|
boolean |
isREF() |
Returns true if the embedded object is a REF and false otherwise.
|
String |
stringValue() |
Returns a string representation of this ANYDATA.
|
String |
stringValue(Connection _connection) |
Returns a string representation of this ANYDATA.
|
Datum |
toDatum(Connection c) |
Extract an oracle.sql.Datum object.
|
Object |
toJDBCObject(Connection c) |
Extract a jdbc Object.
|
public Datum toDatum(Connection c) throws SQLException
ORAData
This method is invoked by setORAData() to extract a Datum. The implementation of this method must return the correct type of Datum.
Although most implementation will ignore the connection, it is occassionally needed. For example, if the class embeds CHAR attributes, connection may be needed to determine the database character set.
toDatum
in interface ORAData
c
- The connection into which the value is being sent.SQLException
- if an error occurred.public Object toJDBCObject(Connection c) throws SQLException
OracleData
This method is invoked by setObject() to extract the jdbc Object. The implementation must return the jdbc Object that correctly represents the underlying SQLType.
Although most implementation will ignore the connection, it is ocassionally needed. for example, if the class embeds CHAR attributes, connection may be needed to determine the database character set.
toJDBCObject
in interface OracleData
c
- The connection into which the value is being sent.SQLException
- if an error occurred.public static ANYDATA convertDatum(Datum datum) throws SQLException
Datum
.SQLException
public TypeDescriptor getTypeDescriptor()
public boolean isNull()
public byte[] getData()
public boolean isREF()
public String stringValue() throws SQLException
For example the following code:
String sql = "select anydata.ConvertDate(TO_DATE('Jan 15, 2006, 11:00 AM', " +" 'Mon dd, YYYY, HH:MI AM')) from dual"; Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(sql); rs.next(); ANYDATA ad = (ANYDATA)rs.getObject(1); System.out.println(ad.stringValue());will print in stdout the following string:
ANYDATA TypeCode: "TYPECODE_DATE" - ANYDATA Value: "1/15/2006 11:0:0"
SQLException
public String stringValue(Connection _connection) throws SQLException
For example the following code:
String sql = "select anydata.ConvertTIMESTAMPTZ(TO_TIMESTAMP_TZ(" +" TIMESTAMP'1997-06-22 08:30:00' AT TIME ZONE 'Asia/Calcutta')) from dual"; Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(sql); rs.next(); ANYDATA ad = (ANYDATA)rs.getObject(1); // Pass connection to the types that require connection to print // eg: oracle.sql.TIMESTAMPTZ, oracle.sql.TIMESTAMPLTZ System.out.println(ad.stringValue(conn));will print in stdout the following string:
ANYDATA TypeCode: "TYPECODE_TIMESTAMP_TZ" - ANYDATA Value: "1997-6-22 21.0.0.0 Asia/Calcutta"
_connection
- OracleConnection objectSQLException
public Datum accessDatum() throws SQLException
getTypeDescripor()
to retrieve type description of this embedded object. You will then be able to cast it to the right oracle.sql.
class.SQLException
protected oracle.jdbc.internal.OracleConnection getConnectionDuringExceptionHandling()