Reference Manual
CHAPTER 7. SQL Data Types
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.
Java classes in the database fall into one of the following categories:
Built-in classes A subset of the Java API is installed into all Java-enabled databases.
User-defined classes Users with DBA permission can install compiled Java classes into a database.
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.
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 )
This section lists the built-in classes available for use as SQL data types in a Java-enabled database.
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 |
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 |
The following table lists the supported classes, interfaces, and exceptions from java.lang.reflect.
Class |
Interface |
Exception |
---|---|---|
Array |
Member |
InvocationTargetException |
Constructor |
||
Field |
||
Method |
||
Modifier |
The following table lists the supported classes from java.math.
Class |
Interface |
Exception |
---|---|---|
BigDecimal |
||
BigInteger |
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 |
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 |
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 |
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 |
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 |
The following packages are not supported in the Sybase VM:
java.applet
java.awt
sun.applet
sun.audio
sun.awt
sun.beans.editors
sun.beans.infos
sun.jdbc.odbc
sun.misc
sun.net
sun.rmi
sun.security
sun.tools
sunw.io
sunw.util
The following classes are only partially supported. They may have some unsupported native methods
java.lang.ClassLoader
java.lang.Compiler
java.lang.Runtime (exec/load/loadlibrary)
java.lang.SecurityManager
java.lang.Thread
java.io.File
java.io.FileDescriptor
java.io.FileInputStream
java.io.FileOutputStream
java.io.ObjectInputStream
java.io.ObjectOutputStream
java.io.ObjectStreamClass
java.io.PrintStream
java.io.RandomAccessFile
java.math.BigInteger
java.net.PlainDatagramSocketImpl
java.util.zip.Adler32
java.util.zip.CRC32
java.util.zip.Deflater
java.util.zip.Inflater
Users with DBA permissions can install Java classes into a database. Any class installed into the database becomes available as a data type.
The Java Development Kit (JDK) provides the tools necessary for preparing classes for installation into a database.
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.
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
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.
From Sybase Central, connect to the database as a user ID with DBA permissions.
Open the Java Objects folder, and double-click Add Java Class or Jar. Follow the instructions in the wizard to install the class.
From Interactive SQL, connect to the database as a user ID with DBA permissions.
Enter the following command to install the class:
INSTALL JAVA NEW FROM filename
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.
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.
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.