Pages

Java

ODBC :
Open DataBase Connectivity, a standard database access method developed by the SQL Access group in 1992. The goal of ODBC is to make it possible to access any data from any application, regardless of which database management system (DBMS) is handling the data. ODBC manages this by inserting a middle layer, called a database driver , between an application and the DBMS. The purpose of this layer is to translate the application's data queries into commands that the DBMS understands. For this to work, both the application and the DBMS must be ODBC-compliant -- that is, the application must be capable of issuing ODBC commands and the DBMS must be capable of responding to them.

 Open Database Connectivity (ODBC) is a way for users to connect to a variety of databases from their own computer.

How to Create an Odbc to Connect to an MS Access 2007 Database

 Instructions




    • 1
      Open the \"Control Panel\" and double-click on \"Administrative Tools.\"
    • 2
      Double-click on \"Data Sources (ODBC)\" to open the snap-in.
    • 3
      Click the \"Add\" button on the \"User DSN\" tab.
    • 4
      Select the \"Microsoft Access Driver (*.mdb, *.accdb)\" from the list of drivers and then click the \"Finish\" button.
    • 5
      Type in a \"Data Source Name\" and click the \"Select\" button in the \"Database\" group.
    • 6
      Search for your database in the list of directories, select it and then click the \"OK\" button.
    • 7
      Click \"OK\" again to finish creating your connection.
    • 8
      Click \"Apply\" and then click \"OK\" to save your changes and close the ODBC window.

This code can be used to retrive and print all qrery data.
Statement stmt = null;
    String query =
        "select COF_NAME, SUP_ID, PRICE, " +
        "SALES, TOTAL " +
        "from " + dbName + ".COFFEES";

    try {
        stmt = con.createStatement();
        ResultSet rs = stmt.executeQuery(query);
        while (rs.next()) {
            String coffeeName = rs.getString("COF_NAME");
            int supplierID = rs.getInt("SUP_ID");
            float price = rs.getFloat("PRICE");
            int sales = rs.getInt("SALES");
            int total = rs.getInt("TOTAL");
            System.out.println(coffeeName + "\t" + supplierID +  "\t" + price + "\t" + sales + "\t" + total);
        }
    } catch (SQLException e ) {
        JDBCTutorialUtilities.printSQLException(e);
    } finally {
        if (stmt != null) { stmt.close(); }
    }


The method ResultSet.next moves the cursor to the next row. This method returns false if the cursor is positioned after the last row. This method repeatedly calls the ResultSet.next method with a while loop to iterate through all the data in the ResultSet.

http://docs.oracle.com/javase/tutorial/uiswing/components/componentlist.html

No comments:

Post a Comment