Java Tutorial - Java Script :
The
The JDBC-ODBC Bridge
ODBC, Microsoft’s common interface for accessing SQL databases, is managed on a Windows system by the ODBC Data Source Administrator. This is run from Control Panel on a Windows system; to get there on most versions of Windows, click Start, Settings, Control Panel, ODBC Data Sources. On Windows XP, choose Start, Control Panel, Performance and Maintenance in Category View or Start, Control Panel in Classic View and then choose Administrative Tools, Data Sources (ODBC).
The administrator adds ODBC drivers, configures drivers to work with specific database files, and logs SQL use. Figure 18.1 shows the ODBC Data Source Administrator on a Windows system. In Figure 18.1, the Drivers tab of the ODBC Data Source Administrator dialog box lists all the ODBC drivers present on the system. Many of the drivers are specific to a database company’s format, such as the Microsoft Access Driver. The JDBC-ODBC bridge allows JDBC drivers to be used as ODBC drivers by converting JDBC method calls into ODBC function calls. Using the JDBC-ODBC bridge requires three things:· The JDBC-ODBC bridge driver included with Java: sun.jdbc.odbc. JdbcOdbcDriver· An ODBC driver · An ODBC data source that has been associated with the driver using software such as the ODBC Data Source AdministratorODBC data sources can be set up from within some database programs. For example, when a new database file is created in Lotus Approach, users have the option of associating it with an ODBC driver All ODBC data sources must be given short, descriptive names. The name is used inside Java programs when a connection is made to the database that the source refers to. On a Windows system, after an ODBC driver is selected and the database is created, they show up in the ODBC Data Source Administrator. Figure 18.2 shows an example of this for a data source named WorldEnergy.
The data source WorldEnergy is associated with a Microsoft Access driver, according to Figure 18.2Connecting to an ODBC Data SourceYour first project today is a Java application that uses a JDBC-ODBC bridge to connect to an Access file. The Access file for this project is world20.mdb, a database of world energy statistics published by the U.S. Energy Information Administration. The Coal table in this database includes three fields you will be using in the project:
· Country · Year · Anthracite Production
The database used in this project is included on this book’s official website at http:// www.java21days.com. To use this database, you must have an ODBC driver on your system that supports Access files. Using the ODBC Data Source Administrator (or a similar program if you’re on a non-Windows system), you must create a new ODBC data source associated with world20.mdb.Other setup work might be needed depending on the ODBC drivers present on your system, if any. Consult the documentation included with the ODBC driver. After you have downloaded world20.mdb to your computer or found another database that’s compatible with the ODBC drivers on your system, the final step in getting the fileready for JDBC-ODBC is to create a data source associated with it.
ODBC, Microsoft’s common interface for accessing SQL databases, is managed on a Windows system by the ODBC Data Source Administrator. This is run from Control Panel on a Windows system; to get there on most versions of Windows, click Start, Settings, Control Panel, ODBC Data Sources. On Windows XP, choose Start, Control Panel, Performance and Maintenance in Category View or Start, Control Panel in Classic View and then choose Administrative Tools, Data Sources (ODBC).
The administrator adds ODBC drivers, configures drivers to work with specific database files, and logs SQL use. Figure 18.1 shows the ODBC Data Source Administrator on a Windows system.
In Figure 18.1, the Drivers tab of the ODBC Data Source Administrator dialog box lists all the ODBC drivers present on the system. Many of the drivers are specific to a database company’s format, such as the Microsoft Access Driver. The JDBC-ODBC bridge allows JDBC drivers to be used as ODBC drivers by converting JDBC method calls into ODBC function calls. Using the JDBC-ODBC bridge requires three things:
· The JDBC-ODBC bridge driver included with Java: sun.jdbc.odbc. JdbcOdbcDriver
· An ODBC driver
· An ODBC data source that has been associated with the driver using software such as the ODBC Data Source Administrator
ODBC data sources can be set up from within some database programs. For example, when a new database file is created in Lotus Approach, users have the option of associating it with an ODBC driver All ODBC data sources must be given short, descriptive names. The name is used inside Java programs when a connection is made to the database that the source refers to. On a Windows system, after an ODBC driver is selected and the database is created, they show up in the ODBC Data Source Administrator. Figure 18.2 shows an example of this for a data source named WorldEnergy.
The data source WorldEnergy is associated with a Microsoft Access driver, according to Figure 18.2
Connecting to an ODBC Data Source
Your first project today is a Java application that uses a JDBC-ODBC bridge to connect to an Access file. The Access file for this project is world20.mdb, a database of world energy statistics published by the U.S. Energy Information Administration. The Coal table in this database includes three fields you will be using in the project:
· Country
· Year
· Anthracite Production
The database used in this project is included on this book’s official website at http:// www.java21days.com. To use this database, you must have an ODBC driver on your system that supports Access files. Using the ODBC Data Source Administrator (or a similar program if you’re on a non-Windows system), you must create a new ODBC data source associated with world20.mdb.
Other setup work might be needed depending on the ODBC drivers present on your system, if any. Consult the documentation included with the ODBC driver. After you have downloaded world20.mdb to your computer or found another database that’s compatible with the ODBC drivers on your system, the final step in getting the fileready for JDBC-ODBC is to create a data source associated with it.
