Java, JDBC, and SQL data type conversions
In this section we discuss about the way MySQL and DB2 UDB handles column 
type to Java data type conversions. As we saw in 5.1,  Data type mapping  on 
page 90, MySQL and DB2 UDB have different data types. As you migrate your 
Java application you should check the Java data types used to fetch your data 
using JDBC. The JDBC driver converts the data exchanged between the 
application and the database using the specified schema mapping, which is 
defined by both DB2 UDB and MySQL for their data types.
Table 7 8, shows MySQL to Java data types. Since MySQL does not enforce a 
strict type conversions, the Java programmer has to take care of data loss 
because of round off, overflow, or precision loss.
Table 7 8   MySQL data type mapping to Java data type
MySQL column type
Java type
Description
CHAR, VARCHAR, BLOB, 
java.lang.String, 
All these columns types 
TEXT, ENUM, and SET
java.io.InputStream, 
can be converted to any of 
java.io.Reader, 
these java data types.
java.sql.Blob, 
java.sql.Clob
FLOAT, REAL, DOUBLE 
java.lang.String, 
round off, overflow or loss 
PRECISION, NUMERIC, 
java.lang.Short, 
of precision may occur if 
DECIMAL, TINYINT, 
java.lang.Integer, 
you choose a Java numeric 
SMALLINT, MEDIUMINT, 
java.lang.Long, 
data type that has less 
INTEGER, BIGINT
java.lang.Double, 
precision or capacity than 
java.math.BigDecimal 
the MySQL data type you 
are converting to/from.
DATE, TIME, DATETIME, 
java.lang.String, 
Locale specific data should 
TIMESTAMP
java.sql.Date, 
be handled with care.
java.sql.Timestamp
On the other hand, DB2 UDB sticks to JDBC specification, and provides a default 
and recommended data type mapping as shown in Table 7 9.
Table 7 9   DB2 UDB data types mapping to Java types
DB2 UDB data type
Java type
 Data type description
SMALLINT
short
16 bit signed integer
INTEGER
int
32 bit signed integer
BIGINT
long
64 bit signed integer
REAL
float
Single precision floating 
point
 Chapter 7. Application porting 
197






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

san diego web hosting

 

Our partners: PHP: Hypertext Preprocessor Cheap Web Hosting JSP Web Hosting Ontario Web Hosting  Jsp Web Hosting

Cheapest Web Hosting Java Hosting Cheapest Hosting

Visionwebhosting.net Business web hosting division of Vision Web Hosting Inc.. All rights reserved