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:
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”;
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://7220.127.116.11.1099/”uses RMI to make the connection to the remote database engine listening on port 1099 at IP Address 192.168.170.27. 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.