Datatype mapping between Java and SQL fields

When you transfer data in either direction between the Java VM and Adaptive Server, you must take into account that the datatypes of the data items are different in each system. Adaptive Server automatically maps SQL items to Java items and vice versa according to the correspondence tables in “Datatype mapping between Java and SQL”.

Thus, SQL type char translates to Java type String, the SQL type binary translates to the Java type byte[], and so on.

In the emps table, the maximum value for the Address and Address2Line classes, street, zip, and line2 fields is 255 bytes (the default value). The Java datatype of these classes is java.String, and they are treated in SQL as varchar(255).

An expression whose datatype is a Java object is converted to the corresponding SQL datatype only when the expression is used in a SQL context. For example, if the field home_addr>>street for employee ‘Smith’ is 260 characters, and begins ‘6789 Main Street ...:

select Misc.getStreet(home_addr>>street) from emps where name='Smith'

The expression in the select list passes the 260-character value of home_addr>>street to the getStreet( ) method (without truncating it to 255 characters). The getStreet( ) method then returns the 255-character string beginning ‘Main Street….’. That 255-character string is now an element of the SQL select list, and is, therefore, converted to the SQL datatype and (if need be) truncated to 255 characters.