Java Methods for connecting Oracle databases

Source: Internet
Author: User
Tags odbc requires zip

Java Interface with Oracle:

Running Java in a database can be said to be the most exciting new feature of Oracle8i. In the application you created to use the Oracle8i database, you can use new Java-related features to easily publish programs to the Internet or intranet.

Methods for Using Java in ORACLE

As you all know, Java has become more popular in cross-platform development and Internet development, and oracle8i and later versions contain extended support for running Java in the database, and there are two ways to use it:

JDBC: Like ODBC, JDBC provides a driver interface that allows you to access a database in a Java program. Note: The JDBC driver is embedded in the virtual machine in the database.

SQLJ: Is a Java precompiled compiler that converts embedded SQL statements into Java statements. The use and operating mechanism of SQLJ is similar to that of other Oracle compilers (such as Pro*c,pro*cobol). In fact, in order to make our image remember the functions provided by SQLJ, we can also directly rename Sqlj to Pro*java.

The integration of Java into the database is bidirectional. That is, you can invoke SQL and Pl/sql in Java, or you can invoke Java in SQL and Pl/sql. Java programs can invoke SQL and pl/sql directly through the JDBC driver, and in turn, you can invoke Java directly in SQL and Pl/sql. In a database, the Java namespace is mapped directly into the database schema's namespace, which facilitates Java access and invocation. The database also provides extended DDL statements that allow you to create embedded Java programs in your data just as you would create a stored procedure.

Features of ORACLE JDBC Drivers

There are three types of JDBC drivers in oracle8i that use the same syntax, APIs, and Oracle extensions to make Java code in robust clients, web-based Java applets, and Lightweight and flexible between Java stored procedures: Three types are as follows:

1.JDBC OCI: This drive is similar to the traditional ODBC driver. Because it requires Oracle call Interface and NET8, it needs to install the client software on the machine running the Java program using this driver

2.JDBC Thin: This drive is typically used in Java programs that run in a Web browser. It communicates through the Java sockets instead of OCI or NET8, so you do not need to install client software on a client machine that uses JDBC thin.

3.JDBC KPRB: This drive is used by Java programs that are stored directly in the database, such as Java Stored procedures, triggers, DB JSP ' s. It uses the Default/current database session and thus requires no additional database username, password or URL.

How to configure Java to connect to a database via Oracle JDBC drivers: 1. Install the Sun JDK.

2. Modify the PATH environment variable so that it points to the JDK bin directory

3. Set the CLASSPATH environment variable so that it points to the correct JDK's lib and Oracle's JDBC interface.

CLASSPATH = ".;????"

3. Run "java–version" to verify the Java version.

How to set up a client based on the interface type on a different operating system:

For JDBC Thin interfaces:

This is the same as the Setup method under Windows and UNIX:

1. According to the JDK version, simply copy the Classesxx.zip to the specified directory without having to install Oracle Client. After the database is loaded, the file is in the $oracle_home/jdbc/lib directory. 2. Set the classpath to include the classesxx.zip above

3. Copy Oracle's other ZIP files and set Classpath as needed

For JDBC OCI interfaces:

FOW Windows:

1. Install Oracle Client.

2. According to the JDK version, set the classpath to include the correct classesxx.zip

3. Set the classpath to point to other Oracle Zip files as needed

4. Set path so that it contains the $oracle_home\bin directory

For Unix:

1. Install Oracle Client.

2. According to the JDK version, set the classpath to include the correct classesxx.zip

3. Set the classpath to point to other Oracle Zip files as needed

4. Set the Ld_library_path to include the $oracle_home/lib directory

Note:

Classesxx.zip is generally in the Oracle_home\jdbc\lib directory.

An explanation of the files related to the Oracle JDBC drives drive in the Oracle_home\jdbc\lib directory:

-Classes12.zip

Classes for use with JDK 1.2.x. It contains the JDBC driver

Classes except classes necessary for NLS support in Object and

Collection types.

-Nls_charset12.zip

NLS classes for use with JDK 1.2.x. It contains classes necessary

For the NLS support in Object and Collection types.

-Classes12_g.zip

Same as Classes12.zip, except that classes were compiled with

"Javac-g".

JDBC Connection syntax for database:

JDBC THIN:

Code: [Copy to Clipboard]

Connection conn=

Drivermanager.getconnection

("Jdbc:oracle:thin: @dlsun511:1521:ora1", "Scott", "Tiger");

|   | |

Machine (ip@): port#: Sid

JDBC OCI:

Code: [Copy to Clipboard]

Connection conn=

Drivermanager.getconnection

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.