|
Oracle JDBC API Reference 11g Release 2 ("11.2.0.3.0") |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object oracle.sql.ANYDATA
public class ANYDATA
This class is the Java mapping of the SYS.ANYDATA SQL type. Instances of this type are self-descriptive. They contain a type description as well the actual content (also called the embedded object).
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. } }
Field Summary | |
---|---|
static java.lang.String |
BUILD_DATE
|
static boolean |
TRACE
|
Method Summary | |
---|---|
Datum |
accessDatum()
Returns the embedded object. |
static ANYDATA |
convertDatum(Datum datum)
Constructs an ANYDATA instance from any instance of Datum . |
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. |
java.lang.String |
stringValue()
Returns a string representation of this ANYDATA. |
java.lang.String |
stringValue(java.sql.Connection _connection)
Returns a string representation of this ANYDATA. |
Datum |
toDatum(java.sql.Connection c)
Extract an oracle.sql.Datum object. |
java.lang.Object |
toJDBCObject(java.sql.Connection c)
Extract a jdbc Object. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String BUILD_DATE
public static final boolean TRACE
Method Detail |
---|
public Datum toDatum(java.sql.Connection c) throws java.sql.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.
java.sql.SQLException
- if an error occurred.public java.lang.Object toJDBCObject(java.sql.Connection c) throws java.sql.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.
java.sql.SQLException
- if an error occurred.public static ANYDATA convertDatum(Datum datum) throws java.sql.SQLException
Datum
.
java.sql.SQLException
public TypeDescriptor getTypeDescriptor()
public boolean isNull()
public byte[] getData()
public boolean isREF()
public java.lang.String stringValue() throws java.sql.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"
java.sql.SQLException
public java.lang.String stringValue(java.sql.Connection _connection) throws java.sql.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 object
java.sql.SQLException
public Datum accessDatum() throws java.sql.SQLException
getTypeDescripor()
to retrieve
type description of this embedded object. You will then be able to cast it to
the right oracle.sql.
class.
java.sql.SQLException
|
Oracle JDBC API Reference 11g Release 2 ("11.2.0.3.0") |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |