Using Java Database Connectivity (JDBC) with Oracle . The DML operations of SELECT, INSERT, UPDATE, and DELETE as well as. PL/SQL procedures and returning of resultsets can be done using. JDBC. Oracle. 8i provides JDBC drivers for Java programs to interface with the. Java programs can call SQL and PL/SQL using the classes in a standard.
Here is a complete code example of Java program to connect Oracle database using. Advance Java » Java Database Connectivity. JDBC consists of Java interfaces that are based on Oracle Database Connectivity (ODBC). Java Simple Program (1) JButtons (1) JCheckBox (1). Oracle supplied packages oracle. The basic steps in creating a JDBC application involve importing JDBC. JDBC driver, opening a connection to the. To process INSERTS, UPDATES, and DELETES, create a Prepared. Statement. object. To invoke PL/SQL subprograms create a Callable. Statement object. Transaction processing involving COMMIT and ROLLBACK is done by setting. OFF and then using the commit() and rollback() methods. Connection object. To manipulate ROWIDS and REF CURSORS use the Oracle Extensions supplied. This chapter explains the use of Java Database Connectivity for database. Java. It highlights the method to incorporate Java in the Oracle 8i. JDBC. The various methods of using JDBC starting from the. DML from the Oracle 8i. The Oracle JDBC extensions are discussed. A. case study is presented to illustrate the concepts. This section gives a brief outline of JDBC and the various JDBC drivers. It. also highlights the JDBC 2. The details of the case study used to. JDBC concepts throughout are presented. About JDBCJDBC provides a standard interface for accessing a relational database from a. Java application regardless of where the application is running and where the. From an Oracle 8i perspective it provides a way for Java. SQL and PL/SQL. In other words it is a way to execute SQL. One important feature of. JDBC is location independence. Java programs with database access can be written. Web- based applet. The ease of. development, robustness, and security of Java programs makes it a good choice. Java. Moreover, the early compile- time. SQL. interface of JDBC for Java. JDBC consists of a high- level . There are. four types of drivers defined by JDBC as follows: Type 1: JDBC/ODBC—These require an ODBC (Open Database. Connectivity) driver for the database to be installed. This type of driver works. ODBC queries and forwards. API calls directly to the ODBC driver. It provides no host. Type. 2: Native API—This type of driver uses a vendor- specific. API to interact with the database. An example of such an API. Oracle OCI (Oracle Call Interface). It also provides no host. Type 3: Open Protocol- Net—This is not vendor specific and. How the net server component accesses the database is. The client driver communicates with the net server. This type of driver can access any. Type 4: Proprietary Protocol- Net—This has a same. Again. this is all transparent to the client. Figure 3. 1 shows a typical implementation. JDBC application. Figure 3. 1 A typical JDBC application. Basically a Java program implementing JDBC performs the following. Load a JDBC driver. Establish a database connection. Optionally interrogate the database for capability subset. Optionally retrieve schema metadata information. Construct a SQL or callable statement object and send queries or database. Execute the database tasks or process resultsets. Close the statement object and resultset. Close the connection. Oracle JDBC Drivers. Oracle 8i provides four types of JDBC drivers, namely, thin drivers, OCI. These. client- side and server- side drivers provide the same functionality and have the. APIs and they share the same Oracle extensions. The difference. lies in how they connect to the database and how they transfer data. The. server- side internal driver supports JDK 1. JDBC 2. 0 whereas the other. JDK 1. 1. x/JDBC 1. Oracle extensions for JDBC 2. The. following gives a detailed description of each of these drivers: Client- side Oracle JDBC Thin Driver. This driver is a Type 4 (Proprietary Protocol- Net) driver and is written in. Java making it platform independent. It allows a direct connection. It implements the TCP/IP protocol that emulates Oracle's. Net. 8 and TTC (the wire protocol of OCI) on top of Java sockets. Java applets. are good candidates that make use of this driver. This driver gives the maximum. Figure 3. 2 shows a client- side. JDBC thin driver. Figure 3. 2 A configuration of an. Oracle client- side JDBC thin driver. Client- side Oracle JDBC OCI Driver. This is a native- API Type 2 driver that is suited for client- server Java. It is Oracle platform- specific and requires an Oracle client. This driver converts JDBC calls into calls to the Oracle Call. Interface using native methods. These calls are then sent to the Oracle database. Net. 8. These drivers support protocols such as IPC, named pipes. TCP/IP, and IPX/SPX. This driver gives the maximum performance for an Oracle. Server- side Oracle JDBC Thin Driver. This driver has the same functionality as the client- side thin driver except. Oracle 8i and accesses a remote database. This driver can. also be used to access data in the same database as the database connection. An. example of using this driver is when accessing an Oracle server from inside of a. Java stored procedure. Server- side Oracle JDBC Internal Driver. This driver supports any Java code that runs inside a target Oracle database. Java stored procedure and must access the same database. JDBC 2. 0 Support. Oracle 8i Release 2 provides JDBC drivers that are fully compliant with Java. JDBC 2. 0. Applications can use these features in exactly the same way as. JDBC. All four Oracle JDBC drivers support these. We will discuss JDBC2. JDK Support. JDBC 2. Features. JDK Support. Oracle 8i Release 2 supports JDK 1. JDK 1. 1. As regards the former, the. JDK 1. 2 versions of the JDBC drivers are fully compliant with JDBC 2. The. implementation is by means of the interfaces in the standard java. On the Oracle side, these interfaces are. The files java. sql.* and oracle. The implementation. JDBC2. 0 functionality is by means of the package oracle. Features such as objects, object references, arrays, and LOBS. The files java. sql.*, oracle. JDK 1. 1. x. The package java. JDK; the packages oracle. Oracle's drivers. JDBC 2. 0 Features. The following are the JDBC 2. Oracle 8i Release 2: Resultset enhancements. JDBC 2. 0 supports scrollable resultset capability under three major. Each. of these resultsets can in turn be Read. The remaining five kinds are. JDBC 2. 0. All these kinds are supported in JDK 1. JDK 1. 1. through an Oracle extension. Batch Updates. Oracle 8i Release 2 supports two types of batch updates, namely. Oracle style and explicit batch update of JDBC 2. Advanced Data Types. The advanced data types such as objects, object references, arrays. LOBS, SQL Data, and Struct are now supported by JDBC 2. With JDK1. 2 compatible. While porting code. JDK1. 1 to JDK 1. JNDIThe Java Naming and Directory Interface (JNDI) is an interface to. This is available as. JDBC2. 0 Optional Package (JDBC 2. Standard Extension API) and. As of Oracle 8i Release 2, this is. JDK1. 2 and JDK1. Connection Pooling. Connection pooling is a method where multiple consumers share a limited. This also. includes connection caching. This is implemented by means of javax. The server- side Oracle JDBC driver does not have connection. Distributed Transactions. A distributed transaction is a combination of two or more related. All the individual. For example, a distributed transaction might involve a change in a. Distributed. transactions are defined as a JDBC2. API and are also. On the Oracle side, support for. OCI and thin drivers and the server- side. Other Features. Other features include fetch size/row prefetching. Fetch size is part. JDBC2. 0 and includes methods to define the number of rows retrieved by each. Oracle row- prefetching can also be used as an equivalent of. JDBC2. 0 fetch size. These features can be used in Oracle 8i Release 2 and JDK. JDK 1. 1. x as an Oracle extension. Case Study. We will use the schema oratest/oratest@oracle (where oracle is the. This is for tools such as SQL*Plus. As part of. the case study we will use the same schema objects as defined in case study of. Chapter 2. These are reproduced here for convenience: Database objects (tables and object types): CREATE TABLE dept (deptno number(4) primary key. CREATE TABLE emp (empno number(1. CREATE TABLE dept.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
January 2017
Categories |