Unformatted text preview:

COP 4610L: JDBC – Part 1 Page 1 Mark Llewellyn ©COP 4610L: Applications in the EnterpriseSpring 2006Introduction To JDBCCOP 4610L: Applications in the EnterpriseSpring 2006Introduction To JDBCSchool of Electrical Engineering and Computer ScienceUniversity of Central FloridaInstructor : Mark [email protected] 242, 823-2790http://www.cs.ucf.edu/courses/cop4610L/spr2006COP 4610L: JDBC – Part 1 Page 2 Mark Llewellyn ©Introduction to JDBC• JDBC was originally an acronym for Java Data Base Connectivity. Sun marketing now states this is no longer an acronym but the official name.• JDBC is made up of about two dozen Java classes in the package java.sql. These classes provide access to relational data stored in a database or other table-oriented forms (like Excel, etc.).• JDBC allows the programmer to use modern database features such as simultaneous connections to several databases, transaction management, precompiled statements with bind variables, calls tostored procedures, and access to metadata in the database dictionary.• JDBC supports both static and dynamic SQL statements.• The evolution of JDBC is shown on the next slide.COP 4610L: JDBC – Part 1 Page 3 Mark Llewellyn ©Evolution of JDBCIncremental improvement and additions over the 2.0 API.javax.sqlNot bundledJDBC 2.1 optional APICan be downloaded from www.java.sun.com/products/jdbc/. Contains database server-side functionality. Prepares the ground for the use of database-aware Java beans.javax.sqlJ2EE and laterJDBC 2.0 optional APIBasic Java client to database connectivity.java.sqlJDK 1.1JDBC 1.0 (previously called 1.2)Adds support for connection pooling, statement pooling, and a migration path to the Connector Architecture.java.sqlJDK 1.4 and laterJDBC 3.0 core APIAdded features such as scrollable result sets, batch updates, new data types for SQL-3, and programmable updates using the result set.java.sqlJDK 1.2 and laterJDBC 2.0 core APIContentsPackage NameBundled withJDBC VersionCOP 4610L: JDBC – Part 1 Page 4 Mark Llewellyn ©Connecting To A Database• A database works in the classic client/server fashion. There is one database and many clients talk to it. (Larger applications may have multiple databases, but they can be considered independently for our purposes.)• As we’ve seen in the earlier sections of notes dealing with networking, the clients are typically remote systems communicating over TCP/IP networks.• In a 2-tier system, the clients talk directly to the database while in a 3-tier system, the clients talk to a business logic server which in turn talks to the database. The business logic server would also contain server-side JDBC functionality.COP 4610L: JDBC – Part 1 Page 5 Mark Llewellyn ©Connecting To A Database (cont.)• A JDBC driver is typically available from the database vendor of the database to which you wish to connect.• There are several different kinds of drivers depending on whether it was written in Java or native code, or whether it talks directly to the database or through another database access protocol (such as Microsoft’s ODBC). From an application programmer’s point of view, none of this matters very much as long as you have a working JDBC driver, you really don’t care how it works (although your client may if its too slow!).• JDBC supports four categories of drivers which are detailed in the table on the next page.COP 4610L: JDBC – Part 1 Page 6 Mark Llewellyn ©JDBC Driver TypesJDBC-to-ODBC Bridge Driver – connects Java to a Microsoft ODBC (Open Database Connectivity) data source. This driver requires the ODBC driver to be installed on the client computer and configuration of the ODBC data source. This driver is used to allow Java programmers to build data-driver Java applications before the database vendor supplies a Type 3 or Type 4 driver. In general, this will not be used too much these days.1Native-protocol Pure Java Drivers – convert JDBC requests to database-specific network protocols, so that Java programs can connect directly to a database.4JDBC-Net Pure Java Drivers – take JDBC requests and translate them into a network protocol that is not database specific. These requests are sent to a server, which translates the database requests into a database-specific protocol.3Native-API, Part Java Drivers – enable JDBC programs to use database-specific APIs (normally written in C or C++) that allow client programs to access databases via the Java Native Interface. This driver translates JDBC into database-specific code. Reasons for use are similar to Type 1.2DescriptionTypeCOP 4610L: JDBC – Part 1 Page 7 Mark Llewellyn ©Some Popular JDBC DriversDriver Name:com.jdbc.odbc.JdbcOdbcDriverDatabase URL format:jdbc:odbc:databaseNameDriver Name:COM.ibm.db2.jdbc.net.DB2DriverDatabase URL format:jdbc:db2:hostname:portnumber/databaseNameDriver Name:oracle.jdbc.driver.OracleDriverDatabase URL format:jdbc:oracle:thin@hostname:portnumber:databaseNameDriver Namecom.mysql.jdbc.DriverDatabase URL format:jdbc:mysql//hostname/databaseNameJDBC Driver NameMySQLAccessDB2OracleRDBMSCOP 4610L: JDBC – Part 1 Page 8 Mark Llewellyn ©Java applicationjava.sql.DriverManagerjava.sql.package(JDBC library)Driver for MySQLdatabasesDriver for OracledatabasesMySQLDB1. Application causes driver to be loaded2. Application asks DriverManager for a connection to a particular DB. DriverManager asks all loaded drivers, and one of them responds with a connection.3. DriverManager gives connection to the application.4. Connection supplied by DriverManager is used by application to talk JDBC through the driver to the database.How JDBC establishes a connection between your code and a databaseCOP 4610L: JDBC – Part 1 Page 9 Mark Llewellyn ©Loading A JDBC Driver• The first step (as illustrated in the previous slide) is to load a JDBC driver. • If your application connects to several different types of databases, all of their respective drivers must be loaded.• The Java statement to load a JDBC driver is:Class.forName(“ JDBC Driver Class “);• You don’t need to create an instance of the driver class. Simply getting the class loaded is enough. Each JDBC driver has a static initializer that is run when the class is loaded, and in that code the driver registers itself with the JDBC. The JDBC driver does about 90% of the work that is done in JDBC.COP 4610L: JDBC – Part 1 Page 10 Mark Llewellyn ©Establishing a Connection• The


View Full Document

UCF COP 4610L - Introduction To JDBC

Download Introduction To JDBC
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Introduction To JDBC and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Introduction To JDBC 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?