Collection Contents Index User-defined data types Data type conversions pdf/chap7.pdf

Reference Manual
   CHAPTER 7. SQL Data Types     

Java class data types


Function 

Any Java class that is installed into a database can be used as a SQL data type. Java class data types provide abstract data types for use within the database.

Built-in and user-defined Java classes 

Java classes in the database fall into one of the following categories:

Top of page  Case sensitivity of Java class data types

Java identifiers, including data types, are case sensitive: the Java int data type cannot be written as INT. SQL identifiers, including data types, are case insensitive. The int data type can also be written as Int or any other combination of upper and lower case characters.

When a Java class is used as a SQL data type, the data type is always case sensitive. This is an exception to the rule for SQL identifier case insensitivity.

Example 

If you install a class named Demo, the following statements are not equivalent:

CREATE TABLE t1 (
   id INT PRIMARY KEY
   demo_column Demo )
CREATE TABLE t1 (
   id INT PRIMARY KEY
   demo_column DEMO )

Top of page  Built-in Java classes

This section lists the built-in classes available for use as SQL data types in a Java-enabled database.

Top of page  java.beans classes

The following table lists the supported classes, interfaces, and exceptions from java.beans.

Class

Interface

Exception

BeanDescriptor

BeanInfo

IntrospectionException

Beans

Customizer

PropertyVetoException

EventSetDescriptor

PropertyChangeListener

FeatureDescriptor

PropertyEditor

IndexedPropertyDescriptor

VetoableChangeListener

Introspector

Visibility

MethodDescriptor

ParameterDescriptor

PropertyChangeEvent

PropertyChangeSupport

PropertyDescriptor

PropertyEditorManager

PropertyEditorSupport

SimpleBeanInfo

VetoableChangeSupport

Top of page  java.lang classes

The following table lists the supported classes, interfaces, and exceptions from java.lang.

Class

Interface

Exception

Boolean

Cloneable

ArithmeticException

Byte

Runnable

ArrayIndexOutOfBoundsException

Character

ArrayStoreException

Class

ClassCastException

ClassLoader

ClassNotFoundException

Compiler

CloneNotSupportedException

Double

Exception

Float

IllegalAccessException

Integer

IllegalArgumentException

Long

IllegalMonitorStateException

Math

IllegalStateException

Number

IllegalThreadStateException

Object

IndexOutOfBoundsException

Process

InstantiationException

Runtime

InterruptedException

( not supported: SecurityManager )

NegativeArraySizeException

Short

NoSuchFieldException

String

NoSuchMethodException

StringBuffer

NullPointerException

System (not supported: Thread, ThreadGroup)

NumberFormatException

Throwable

RuntimeException

Void

SecurityException

StringIndexOutOfBoundsException

Top of page  java.lang.reflect classes

The following table lists the supported classes, interfaces, and exceptions from java.lang.reflect.

Class

Interface

Exception

Array

Member

InvocationTargetException

Constructor

Field

Method

Modifier

Top of page  java.math classes

The following table lists the supported classes from java.math.

Class

Interface

Exception

BigDecimal

BigInteger

Top of page  java.sql classes

The following table lists the supported classes, interfaces, and exceptions from java.sql.

Class

Interface

Exception

Date

CallableStatement

DataTruncation

DriverManager

Connection

SQLException

DriverPropertyInfo

DatabaseMetaData

SQLWarning

Time

Driver

Timestamp

PreparedStatement

Types

ResultSet

ResultSetMetaData

Statement

Top of page  java.text classes

The following table lists the supported classes, interfaces, and exceptions from java.text.

Class

Interface

Exception

BreakIterator

CharacterIterator

ParseException

ChoiceFormat

CollationElementIterator

CollationKey

Collator

DateFormat

DateFormatSymbols

DecimalFormat

DecimalFormatSymbols

FieldPosition

Format

MessageFormat

NumberFormat

ParsePosition

RuleBasedCollator

SimpleDateFormat

StringCharacterIterator

Top of page  java.util classes

The following table lists the supported classes, interfaces, and exceptions from java.util.

Class

Interface

Exception

BitSet

Enumeration

EmptyStackException

Calendar

EventListener

MissingResourceException

Date

Observer

NoSuchElementException

Dictionary

TooManyListenersException

EventObject

GregorianCalendar

Hashtable

ListResourceBundle

Locale

Observable

Properties

PropertyResourceBundle

Random

ResourceBundle

SimpleTimeZone

Stack

StringTokenizer

TimeZone

Vector

Top of page  java.util.zip classes (Compression utilities)

The following table lists the supported classes, interfaces, and exceptions from java.util.

Class

Interface

Exception

Adler32

Checksum

DataFormatException

CRC32

ZipException

CheckedInputStream

CheckedOutputStream

Deflater

DeflaterOutputStream

GZIPInputStream

GZIPOutputStream

Inflater

InflaterInputStream

ZipEntry

ZipFile

ZipInputStream

ZipOutputStream

Top of page  java.io classes

The following table lists the supported classes, interfaces, and exceptions from java.io.

Class

Interface

Exception

BufferedInputStream

DataInput

CharConversionException

BufferedOutputStream

DataOutput

EOFException

BufferedReader

Externalizable

FileNotFoundException

BufferedWriter

FilenameFilter

IOException

ByteArrayInputStream

ObjectInput

InterruptedIOException

ByteArrayOutputStream

ObjectInputValidation

InvalidClassException

CharArrayReader

ObjectOutput

InvalidObjectException

CharArrayWriter

Serializable

NotActiveException

DataInputStream

NotSerializableException

DataOutputStream

ObjectStreamException

File

OptionalDataException

FileDescriptor

StreamCorruptedException

FileInputStream

SyncFailedException

FileOutputStream

UTFDataFormatException

FileReader

UnsupportedEncodingException

FileWriter

WriteAbortedException

FilterInputStream

FilterOutputStream

FilterReader

FilterWriter

InputStream

InputStreamReader

LineNumberInputStream

LineNumberReader

ObjectInputStream

ObjectOutputStream

ObjectStreamClass

OutputStream

OutputStreamWriter

PipedInputStream

PipedOutputStream

PipedReader

PipedWriter

PrintStream

PrintWriter

PushbackInputStream

PushbackReader

RandomAccessFile

Reader

SequenceInputStream

StreamTokenizer

StringBufferInputStream

StringReader

StringWriter

Writer

Top of page  Unsupported packages and classes

The following packages are not supported in the Sybase VM:

The following classes are only partially supported. They may have some unsupported native methods

Top of page  User-defined Java classes

Users with DBA permissions can install Java classes into a database. Any class installed into the database becomes available as a data type.

Preparing classes using the JDK 

The Java Development Kit (JDK) provides the tools necessary for preparing classes for installation into a database.

  To prepare a class for installation, using the JDK:
  1. Using a text editor, write a Java class, outside the database, and store it as a Java source code file (typically with an extension of .java).

    For example, you may create a file named MyFirstClass.java.

  2. Using the javac compiler, compile the Java class to produce a Java class file (with .class extension).

    For example, to compile the file MyFirstClass.java, type the following at a command prompt:

    javac MyFirstClass.java

Installing a class 

Once you have a compiled Java class file, you can install it into the database. You can do this conveniently using either Sybase Central or Interactive SQL.

  To install a class, using Sybase Central:
  1. From Sybase Central, connect to the database as a user ID with DBA permissions.

  2. Open the Java Objects folder, and double-click Add Java Class or Jar. Follow the instructions in the wizard to install the class.

  To install a class, using Interactive SQL:
  1. From Interactive SQL, connect to the database as a user ID with DBA permissions.

  2. Enter the following command to install the class:

    INSTALL JAVA NEW FROM filename

Top of page  Using classes as data types

Creating tables using Java class data types 

You can create a table with columns based on a Java class data type, just as you can with any other data type. For example, if MyClass is a Java class installed into the database, you can create a table using this class as follows:

CREATE TABLE mytable (
   id INT NOT NULL PRIMARY KEY,
   mycol MyClass )

In this statement, the MyClass data type is a SQL data type, and so is case-insensitive, even though Java is a case-sensitive language.

Inserting Java objects 

You can insert a Java object into a table just as you would any other row, using the INSERT statement. Because each row is a separate instance of the class, you must use the NEW keyword to create an instance. For example,

INSERT INTO t2
VALUES ( 1, NEW MyClass() )

In this case, MyClass() is a Java class name, not a SQL data type, and so must be entered in the proper case.

In this example, MyClass() has no arguments, so each row is created using the default constructor. In general, you would supply arguments to a class to place distinct values in each row.

Using subclasses 

If you install a class, say MySubClass, which is a subclass of MyClass, you can insert instances of MySubClass into a column of data type MyClass.

Top of page  

Collection Contents Index User-defined data types Data type conversions pdf/chap7.pdf