• JDBC [Java DataBase Connectivity]

    JDBC [Java DataBase Connectivity]


    It has been estimated that half of all software development involves client/server operations. A great promise of Java has been the ability to build platform-independent client/server database applications. This has come to fruition with JDBC [Java DataBase Connectivity].

    JDBC, like many of the APIs in Java, is designed for simplicity. The method calls you make correspond to the logical operations you’d think of doing when gathering data from a database: connect to the database, create a statement and execute the query, and look at the result set.

    To allow this platform independence, JDBC provides a driver manager that dynamically maintains all the driver objects that your database queries will need. So if you have three different kinds of vendor databases to connect to, you’ll need three different driver objects. The driver objects register themselves with the driver manager at the time of loading, and you can see force the loading using Class.forName().

    To open a database, you must create a “database URL” that specifies:

    1. That you’re using JDBC with “jdbc”.
    2. The “subprotocol”: the name of the driver or the name of a database connectivity mechanism. Since the design of JDBC was inspired by ODBC, the first subprotocol available is the “jdbc-odbc bridge,“ specified by “odbc”.
    3. The database identifier. This varies with the database driver used, but it generally provides a logical name that is mapped by the database administration software to a physical directory where the database tables are located. For your database identifier to have any meaning, you must register the name using your database administration software.

    All this information is combined into one string, the “database URL”. For example, to connect through the ODBC subprotocol to a database identified as “student,” the database URL could be:

    String dbUrl = “jdbc:odbc:people”;

    JDBC with RMI:

    If you’re connecting across a network, the database URL will contain the connection information identifying the remote machine and can become a bit intimidating. Here is an example of a CloudScape database being called from a remote client utilizing RMI:


    This database URL is really two jdbc calls in one. The first part “jdbc:rmi://792.”uses RMI to make the connection to the remote database engine listening on port 1099 at IP Address the second part of the URL, “jdbc:cloudscape:db” Conveys the more typical settings using the subprotocol and database name but this will only happen after the first section has made the connection via RMI to the remote machine.

    When you are ready to connect to the database, call the static method DriverManager.getConnection() and pass it the database URL, the user name, and a password to get into the database. You get back a Connection object that you can then use to query and manipulate the database.

    Appreciate my work :Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInPin on PinterestShare on RedditShare on StumbleUponShare on TumblrDigg thisShare on YummlyShare on VKFlattr the authorBuffer this page

Leave a Reply

Your email address will not be published. Required fields are marked *