JavaDeploy JavaDeploy


JDBC - Part 1  «Prev  Next»
  1. What is JDBC?

    Answer:
    JDBC stands for Java Database Connectivity.
    JDBC is a layer of abstraction that allows users to choose between databases.
    It allows you to change to a different database engine and to write to a single API. JDBC allows you to write database applications in Java without having to concern yourself with the underlying details of a particular database.

  2. What are the two major components of JDBC?

    Answer:
    One implementation interface for database manufacturers, the other implementation interface for application and applet writers.

  3. What is JDBC Driver interface?

    Answer:
    The JDBC Driver interface provides vendor-specific implementations of the abstract classes provided by the JDBC API.
    Each vendors driver must provide implementations of the
    1. java.sql.Connection,
    2. Statement,
    3. PreparedStatement,
    4. CallableStatement,
    5. ResultSet and
    6. Driver.

  4. What are the common tasks of JDBC?

    Answer:
    1. Create an instance of a JDBC driver or load JDBC drivers through jdbc.drivers
    2. Register a driver
    3. Specify a database
    4. Open a database connection
    5. Submit a query
    6. Receive results

  5. How to use JDBC to connect to Microsoft Access?

    Answer:
    There are two techniques available for connecting to a data source using JDBC. First, if your program will talk to an ODBC data source, you can use the JDBC-ODBC bridge included with your JDK.
    In the case of Sun, you would use sun.jdbc.odbc.JbdcOdbcDriver.
    Specifically, using Class.forName:

    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    

    or the command line:

    java -Djdbc.drivers=sun.jdbc.odbc.JdbcOdbcDriver < program name >
    

    Second, you can connect to your data source through a third-party, vendor-specific bridge.
    In the case of a third party driver, you simply substitute that driver for the JDBC-ODBC bridge driver.

  6. What are four types of JDBC driver?

    Answer:
    1. Type 1 Drivers
      Bridge drivers such as the jdbc-odbc bridge.
      They rely on an intermediary such as ODBC to transfer the SQL calls to the database and also often rely on native code.
    2. Type 2 Drivers
      Use the existing database API to communicate with the database on the client.
      Faster than Type 1, but need native code and require additional permissions to work in an applet. Good for client-side connection.
    3. Type 3 Drivers : Java Protocol
      Call the database API on the server. Type 3 JDBC drivers translate queries into JDBC-formatted statements, which are then converted to the format required by the DBMS.
      Pure Java and no native code.
    4. Type 4 Drivers
      The hightest level of driver reimplements the database network API in Java. No native code.

  7. What packages are used by JDBC?
    Answer:

    There are at least 8 packages:
    1. java.sql.Driver
    2. Connection
    3. Statement
    4. PreparedStatement
    5. CallableStatement
    6. ResultSet
    7. ResultSetMetaData
    8. DatabaseMetaData

  8. There are three basic types of SQL statements, what are they?
    Answer:

    1. Statement
    2. CallableStatement
    3. PreparedStatement

  9. What are the flow statements of JDBC?
    Answer:

    A URL string -->getConnection-->DriverManager-->Driver-->Connection-->
    Statement-->executeQuery-->ResultSet.

  10. What are the steps involved in establishing a connection?
    Answer:

    This involves two steps:
    1. loading the driver and
    2. making the connection.