0% found this document useful (0 votes)
72 views

Java SQL Tipos Equivalencias

The document discusses mappings between Java data types and database data types for use in JDBC and SQLJ programs. It provides tables summarizing the recommended mappings for updating databases, retrieving data, and calling stored procedures or user-defined functions.

Uploaded by

cesar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
72 views

Java SQL Tipos Equivalencias

The document discusses mappings between Java data types and database data types for use in JDBC and SQLJ programs. It provides tables summarizing the recommended mappings for updating databases, retrieving data, and calling stored procedures or user-defined functions.

Uploaded by

cesar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Data types that map to database data types in Java applications

To write efficient JDBC and SQLJ programs, you need to use the best mappings between
Java data types and table column data types.
The following tables summarize the mappings of Java data types to JDBC and database data
types for a DB2 Database for Linux, UNIX, and Windows, DB2 for z/OS, or IBM
Informix Dynamic Server (IDS) system.

Data types for updating table columns


The following table summarizes the mappings of Java data types to database data types
for PreparedStatement.setXXX or ResultSet.updateXXXmethods in JDBC programs. When
more than one Java data type is listed, the first data type is the recommended data type.

Table 1. Mappings of Java data types to database server data types for updating
database tables
Java data type

Database data type

short

SMALLINT

short

BOOLEAN

boolean, java.lang.Boolean

BOOLEAN

int, java.lang.Integer

INTEGER

int, java.lang.Integer

SERIAL

long, java.lang.Long

INT8

long, java.lang.Long

BIGINT

long, java.lang.Long

SERIAL8

long, java.lang.Long

BIGSERIAL

float, java.lang.Float

SMALLFLOAT

double, java.lang.Double

FLOAT

java.math.BigDecimal

DECIMAL(p,s)1

java.math.BigDecimal

DECIMAL(p)2

java.math.BigDecimal

DECIMAL3

Table 1. Mappings of Java data types to database server data types for updating
database tables
Java data type

Database data type

java.math.BigDecimal

MONEY(p,s)1

java.lang.String

CHAR(n)4

java.lang.String

NCHAR(n)4

java.lang.String

VARCHAR(m,r)5

java.lang.String

LVARCHAR(m,r)6

java.lang.String

NVARCHAR(m,r)6

java.lang.String

INTERVAL

java.lang.String

CLOB7

byte[]

BYTE

byte[]

BLOB7

java.sql.Blob

BLOB

java.sql.Clob

CLOB

java.lang.Clob

TEXT

java.sql.Date

DATE

java.sql.Time

DATETIME HOUR TO SECOND

java.sql.Timestamp

DATETIME YEAR TO FRACTION(5)

java.io.ByteArrayInputStream

BLOB

java.io.StringReader

CLOB

java.io.ByteArrayInputStream

CLOB

Notes:
1. p is the decimal precision and s is the scale of the table column.

Table 1. Mappings of Java data types to database server data types for updating
database tables
Java data type

Database data type

2. For an ANSI-compliant database, p is the precision, and the scale is 0. For a


database that is not ANSI-compliant, if you specify onlyp, the data type is
DECIMAL floating point.
3. For an ANSI-compliant database, if you specify no parameters, the precision is 16
and the scale is 0. For a database that is not ANSI-compliant, if you specify no
parameters, the data type is DECIMAL floating point.
4. n<=32767.
5. 0<=r<=m<=255.
6. 0<=r<=m<=32739.
7. This mapping is valid only if the database server can determine the data type of the
column.

Data types for retrieval from table columns


The following table summarizes the mappings of DB2 or IDS data types to Java data types
for ResultSet.getXXX methods in JDBC programs, and for iterators in SQLJ programs. This
table does not list Java numeric wrapper object types, which are retrieved
using ResultSet.getObject.

Table 2. Mappings of database server data types to Java data types for retrieving data
from database server tables

SQL data type

Recommended Java
data type or Java
object type

Other supported Java


data types

SMALLINT

short

byte, int, long, float,


double,
java.math.BigDecimal,
boolean,
java.lang.String

BOOLEAN

boolean

short

INTEGER

int

short, byte, long, float,


double,
java.math.BigDecimal,
boolean,
java.lang.String

SERIAL

int

short, byte, long, float,


double,
java.math.BigDecimal,
boolean,

Table 2. Mappings of database server data types to Java data types for retrieving data
from database server tables

SQL data type

Recommended Java
data type or Java
object type

Other supported Java


data types
java.lang.String

INT8

long

int, short, byte, float,


double,
java.math.BigDecimal,
boolean,
java.lang.String

BIGINT

long

int, short, byte, float,


double,
java.math.BigDecimal,
boolean,
java.lang.String

SERIAL8

long

int, short, byte, float,


double,
java.math.BigDecimal,
boolean,
java.lang.String

BIGSERIAL

long

int, short, byte, float,


double,
java.math.BigDecimal,
boolean,
java.lang.String

DECIMAL(p,s)

java.math.BigDecimal

long, int, short, byte,


float, double, boolean,
java.lang.String

DECIMAL(p)

java.math.BigDecimal

long, int, short, byte,


float, double,
java.math.BigDecimal,
boolean,
java.lang.String

MONEY(p,s)

java.math.BigDecimal

long, int, short, byte,


float, double, boolean,
java.lang.String

SMALLFLOAT

float

long, int, short, byte,


double,

Table 2. Mappings of database server data types to Java data types for retrieving data
from database server tables

SQL data type

Recommended Java
data type or Java
object type

Other supported Java


data types
java.math.BigDecimal,
boolean,
java.lang.String

FLOAT

double

long, int, short, byte,


float,
java.math.BigDecimal,
boolean,
java.lang.String

CHAR(n)

java.lang.String

long, int, short, byte,


float, double,
java.math.BigDecimal,
boolean, java.sql.Date,
java.sql.Time,
java.sql.Timestamp,
java.io.InputStream,
java.io.Reader

NCHAR(n)

java.lang.String

long, int, short, byte,


float, double,
java.math.BigDecimal,
boolean, java.sql.Date,
java.sql.Time,
java.sql.Timestamp,
java.io.InputStream,
java.io.Reader

VARCHAR(m,r)

java.lang.String

long, int, short, byte,


float, double,
java.math.BigDecimal,
boolean, java.sql.Date,
java.sql.Time,
java.sql.Timestamp,
java.io.InputStream,
java.io.Reader

LVARCHAR(m,r)

java.lang.String

long, int, short, byte,


float, double,
java.math.BigDecimal,
boolean, java.sql.Date,
java.sql.Time,
java.sql.Timestamp,

Table 2. Mappings of database server data types to Java data types for retrieving data
from database server tables

SQL data type

Recommended Java
data type or Java
object type

Other supported Java


data types
java.io.InputStream,
java.io.Reader

NVARCHAR(n)

java.lang.String

long, int, short, byte,


float, double,
java.math.BigDecimal,
boolean, java.sql.Date,
java.sql.Time,
java.sql.Timestamp,
java.io.InputStream,
java.io.Reader

INTERVAL

java.lang.String

long, int, short, byte,


float, double,
java.math.BigDecimal,
boolean, java.sql.Date,
java.sql.Time,
java.sql.Timestamp,
java.io.InputStream,
java.io.Reader

BYTE

byte[]

None

CLOB(n)

java.sql.Clob

java.lang.String

TEXT

java.sql.Clob

java.lang.String

BLOB(n)

java.sql.Blob

byte[]1

DATE

java.sql.Date

java.sql.String,
java.sql.Timestamp

DATETIME HOUR TO
SECOND

java.sql.Time

java.sql.String,
java.sql.Timestamp

DATETIME YEAR TO
FRACTION(5)

java.sql.Timestamp

java.sql.String,
java.sql.Date,
java.sql.Time,
java.sql.Timestamp

Notes:

Table 2. Mappings of database server data types to Java data types for retrieving data
from database server tables

SQL data type

Recommended Java
data type or Java
object type

Other supported Java


data types

1. This mapping is valid only if the database server can determine the data type of the
column.

Data types for calling stored procedures and user-defined functions


The following table summarizes mappings of Java data types to JDBC data types and DB2 or
IDS data types for calling user-defined function and stored procedure parameters. The
mappings of Java data types to JDBC data types are
for CallableStatement.registerOutParameter methods in JDBC programs. The mappings of Java
data types to database server data types are for parameters in stored procedure or user-defined
function invocations.
If more than one Java data type is listed in the following table, the first data type is
the recommended data type.

Table 3. Mappings of Java, JDBC, and SQL data types for calling stored procedures
and user-defined functions
Java data type

JDBC data type

SQL data type

boolean

BIT

BOOLEAN

boolean

BOOLEAN

BOOLEAN

byte1

TINYINT

SMALLINT

short, java.lang.Short

SMALLINT

SMALLINT

int, java.lang.Integer

INTEGER

INTEGER

int, java.lang.Integer

INTEGER

SERIAL

long

BIGINT

INT8

long

BIGINT

BIGINT

long

BIGINT

SERIAL8

long

BIGINT

BIGSERIAL

Table 3. Mappings of Java, JDBC, and SQL data types for calling stored procedures
and user-defined functions
Java data type

JDBC data type

SQL data type

float, java.lang.Float

REAL

SMALLFLOAT

float, java.lang.Float

FLOAT

SMALLFLOAT

double, java.lang.Double

DOUBLE

FLOAT

java.math.BigDecimal

NUMERIC

DECIMAL

java.math.BigDecimal

DECIMAL

DECIMAL

java.math.BigDecimal

NUMERIC

MONEY

java.lang.String

CHAR

CHAR

java.lang.String

CHAR

INTERVAL

java.lang.String

CHAR

NCHAR

java.lang.String

VARCHAR

VARCHAR

java.lang.String

VARCHAR

NVARCHAR

java.lang.String

LONGVARCHAR

VARCHAR

java.lang.String

LONGVARCHAR

LVARCHAR

java.lang.String

VARCHAR

CLOB

java.lang.String

LONGVARCHAR

CLOB

java.lang.String

CLOB

CLOB

java.lang.String

CLOB

TEXT

byte[]

BINARY

BYTE

byte[]

VARBINARY

BYTE

byte[]

VARBINARY

BYTE

Table 3. Mappings of Java, JDBC, and SQL data types for calling stored procedures
and user-defined functions
Java data type

JDBC data type

SQL data type

byte[]

LONGVARBINARY

BYTE

byte[]

LONGVARBINARY

BLOB2

java.sql.Date

DATE

DATE

java.sql.Time

TIME

DATETIME
HOUR TO
SECOND

java.sql.Timestamp

TIMESTAMP

DATETIME
YEAR TO
FRACTION(5)

java.sql.Blob

BLOB

BLOB

java.sql.Clob

CLOB

CLOB

java.io.ByteArrayInputStream

None

BLOB

java.io.StringReader

None

CLOB

java.io.ByteArrayInputStream

None

CLOB

You might also like