Java Reference
In-Depth Information
Table 3-1: Standard SQL Data Types with Their Java Equivalents
SQL type
Java Type
Description
FLOAT
double
Floating-point number, mapped to double
INTEGER
int
32-bit integer values
LONGVARBINARY
byte[]
Variable-length character string. JDBC
allows retrieval of a LONGVARBINARY as a
Java input stream.
LONGVARCHAR
String
Variable-length character string. JDBC
allows retrieval of a LONGVARCHAR as a
Java input stream.
NCHAR
String
National Character Unicode fixed-length
character string
NUMERIC
java.math.BigDecimal
Arbitrary-precision signed decimal numbers.
Can be retrieved using either BigDecimal or
String.
NTEXT
String
Large string variables. Used for character
large objects.
NVARCHAR
String
National Character Unicode variable-length
character string
REAL
float
Floating-point number, mapped to float
SMALLINT
short
16-bit integer values
TIME
java.sql.Time
Thin wrapper around java.util.Date
TIMESTAMP
java.sql.Timestamp
Composite of a java.util.Date and a separate
nanosecond value
VARBINARY
byte[]
Byte array
VARCHAR
String
Variable-length character string. For a
VARCHAR of length n, the DBMS assigns
upto n charcters of storage, as required.
Many SQL dialects also support additional data types, such as a MONEY or
CURRENCY type. These are handled in Java using the most appropriate getter and
setter methods.
Data of any SQL data type can be retrieved using the getObject() method. This is
particularly useful if you don't know the data type, and can derive it elsewhere in the
application. In addition, data of many types can be retrieved using getString(), and
Search WWH ::




Custom Search