Java Home | Java Certification | Java Scratchbook

Using MS Access

If you are a Windows NT or Windows 95 user and have Microsoft Access software, you can access Microsoft Access tables using an ODBC/JDBC bridge driver that comes with the JDK (see ODBC documentation of the JDK). This section explains how to set up MS Access on a Windows NT computer so you can access You'll set up some MS Access data that you can access.

Configuring your system for MS Access

To set up Microsoft Access and configure it to work with the TableExample2 application, follow these steps:

  1. If MS Access isn't installed on your computer, install it in accordance with instructions provided by Microsoft.
  2. From the Windows NT desktop, open the examples directory where your Access database is located.
  3. From the Windows NT Control Panel, double-click the System icon. When the System Properties dialog box opens, tab to the Environment page and create a user variable named JDBCHOME.
  4. Click the System Properties dialog box's Set button. That action sets the JDBCHOME directory to point to the DBDemos subdirectory inside your examples directory -- for example, set JDBCHOME to C:\mydir\examples\DBDemos
  5. Close the System Properties dialog box by clicking OK.
  6. From the Windows NT control panel, double-click the ODBC32 icon. When the "ODBC Data Source Administrator" dialog box opens, click the Add Button. Then, when the "Create New Data Source" dialog opens, select the item labeled "Microsoft Access Driver (*.mdb)" and click the Finish button. Windows then opens a dialog box named "ODBC Microsoft Access 97 Setup."
  7. When the "ODBC Microsoft Access 97 Setup" dialog appears, click the Select button. Windows then opens another dialog titled "Select Database."
  8. In the "Select Database" dialog box, navigate to the examples\DBDemos\JavaDB subdirectory inside examples directory.
  9. Notice that the entry "CAFEJAVA.MDB" appears inside the Select Database dialog's "Database Name" text field. Select the "CAFEJAVA.MDB" entry and confirm that it has been copied into the Database name text field.
  10. Close the "Select Database," "ODBC Microsoft Access 97 Setup," and "ODBC Data Source Administrator" dialog boxes by clicking their OK buttons.
You have now connected your computer's ODBC mechanism to an Access database named CafeJava.mdb, which resides in your examples\DBDemos\JavaDB directory. Also, you have made the CafeJava.mdb database an ODBC/JDBC data source named CafeJava.

Connecting to a database

When the JDBC adapter is called using these parameters, it prints the line "Opening db connection" in your application's terminal window and then attempts to open the database you have specified by calling a JDBC method named DriverManager.getConnection():

                       public JDBCAdapter(String url, String 
                            driverName, String user, 
                               String passwd) {
                            try {
                                Class.forName(driverName);
                                System.out.println\
                                   ("Opening db connection");

                                connection = 
                                   DriverManager.getConnection
                                   (url, user, passwd);
                                statement = 
                                   connection.createStatement();
                            }
                            catch (Exception ex) {
                                ex.printStackTrace();
                            }    
                         }

Java Home


{submenus}
DISCLAIMER
   
 
Setting MS-Access 97 with ODBC-JDBC

 

1