Data types that map to database data types in Java applications To write efficient JDBC and SQLJ programs, you need to u
Views 74 Downloads 0 File size 260KB
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