As the number of tables that need to be populated increases, you'll need to write more code. But even this is only the case for a single database. If the data is ported to a different database system, you must rewrite all the existing code to account for the different data types in the new database. The issue of cross-database data typing has earned well-deserved notoriety in database programming.
DatabaseMetaData interface in the java.sql package. By writing to this interface, you avoid the hardcoding of data types and develop generic, reusable code. The DatabaseMetaData interface provides metadata information for a database. Metadata is data that describes data. For instance, our airline database table contains ticketing information. This is data. In this
scenario, metadata would contain information on things like the number of columns in the table, the data types of these columns,
whether a column can have null values, and so on. This is data about data. The specific focus of this article is on the data
types of columns. In the following discussion, I will show you how to develop a reusable library of three Java classes that
are organized in layers, from closest to the database to farthest. The farthest layer from the database becomes the nearest
layer to the application that uses the library. Although this library is meant for populating a database table, you can use
the techniques illustrated in building it, as well as some of the code, to build libraries for data-type-independent database
queries and updates.emp in an organization database. Here is a sample data file that contains the table name on the first line, and a set of column
names in the second. Every subsequent line contains row data for the specified columns. emp |
sal |
ename |
empno |
1996-09-01 |
1250.00 |
jackson |
7123 |
1980-01-01 |
2500.50 |
walsh |
7124 |
1985-01-01 |
12345.67 |
gates |
7125 |
While all input data is ASCII text, the data in these columns will be translated to the following database-specific types: