Java links oracle11g R2

Source: Internet
Author: User

Rookie learn Oracle database, use Java code to link database.

First configure eclipse, in the new project, the package explorer-> project name->build path->add external archives->oracle installation disk X:\app\admin\ Product\11.2.0\dbhome_1\jdbc\lib\ojdbc*.jar

Ojdbc the selection of the jar package refer to the Readme file.


For all platforms:

[Oracle_home]/jdbc/lib contains:

-Ojdbc5.jar
Classes with JDK 1.5. It contains the JDBC driver
Classes, except classes for NLS support in Oracle Object and
Collection types.

-Ojdbc5_g.jar
Same as Ojdbc5.jar, except that classes were compiled with
"Javac-g" and contain tracing code.

-Ojdbc5dms.jar
Same as Ojdbc5.jar, except that it contains instrumentation to
Support DMS and limited java.util.logging calls.

-Ojdbc5dms_g.jar
Same as Ojdbc5_g.jar, except that it contains instrumentation to
Support DMS.

-Ojdbc6.jar
Classes with JDK 1.6. It contains the JDBC driver classes
Except classes for NLS support in Oracle Object and Collection
Types.

-Ojdbc6_g.jar
Same as Ojdbc6.jar except compiled with "Javac-g" and contains
Tracing code.

-Ojdbc6dms.jar
Same as Ojdbc6.jar, except that it contains instrumentation to
Support DMS and limited java.util.logging calls.

-Ojdbc6dms_g.jar
Same as Ojdbc6_g.jar except that it contains instrumentation to
Support DMS.

Note:the DMS versions of the jar files are the same as
Standard jar files, except that they contain additional code
To support Oracle Dynamic monitoring Service. They contain a
Limited amount of tracing code. These can only be used
When Dms.jar are in the classpath. Dms.jar is provided as part of
Oracle Application Server releases. As a result the DMS versions
Of the jar files can only is used in an Oracle application Server
Environment.

[Oracle_home]/jdbc/doc/javadoc.tar contains the JDBC Javadoc
For the public API, the public classes of Oracle JDBC. This
JAVADOC is the primary reference for Oracle JDBC API extensions. The
Oracle JDBC Development Guide contains-level discussion of
Oracle extensions. The details is in this JavaDoc. The JAVADOC is
Every bit as authorative as the Dev Guide.

[Oracle_home]/jdbc/demo/demo.tar contains sample JDBC programs.

[Oracle_home]/jlib/orai18n.jar
NLS classes for use with JDK 1.5, and 1.6. It contains
Classes for NLS support in Oracle Object and Collection types.
This jar file replaces the old nls_charset jar/zip files. Inch
Oracle 10g R1 It is duplicated in [Oracle_home]/jdbc/lib. We
has removed the duplicate copy and you should now get it from
Its proper location.


For the Windows platform:

[Oracle_home]\bin directory contains Ocijdbc11.dll and
Heteroxa11.dll, which is the libraries used by the JDBC OCI
Driver.

For non-windows platforms:

[Oracle_home]/lib directory contains libocijdbc11.so,
Libocijdbc11_g.so, libheteroxa11.so and libheteroxa11_g.so, which
is the shared libraries used by the JDBC OCI driver.

The Java code is as follows:

 Packageconnection.oracle;ImportJava.sql.*; Public classJava_connectoracle_jdb {/**     * @paramargs*/     Public Static voidMain (string[] args) {//TODO auto-generated Method Stub        Try {            //Load DriverClass.forName ("Oracle.jdbc.driver.OracleDriver"); //Get ConnectedConnection ct =Drivermanager.getconnection ("Jdbc:oracle:thin:@127.0.0.1:1521:orcl", "Scott", "123456"); //Connection//ct=drivermanager.getconnection ("jdbc:oracle:thin:@127.0.0.1:1521: Instance Name (SID)",//"User name", "password");Statement SM =ct.createstatement (); ResultSet RS= Sm.executequery ("SELECT * from Salgrade"); System.out.println ("Grade-losal-hisal");  while(Rs.next ()) {System.out.println ("Salgrade:" + rs.getstring (1) + "-" + rs.getstring (2) + "-" + rs.getstring (3));            } rs.close ();            Sm.close ();        Ct.close (); } Catch(Exception e) {e.printstacktrace (); }    }}

As follows:

Use of JDBC:

Some Useful Hints in Using the JDBC Drivers-------------------------------------------refer to"JDBC Developer ' s Guide and Reference" fordetailsregarding usage of Oracle' s JDBC Drivers. This section is only offersuseful hints. These hints is not meant to be exhaustive. These is a few simple things it should DoIn your JDBC program:1.    Import the necessary JDBC classes in your programs this use JDBC. For example:ImportJava.sql.*; Importjava.math.*;//if neededto use Oracledatasource, your need to Do:      ImportOracle.jdbc.pool.OracleDataSource;2.       Create an Oracledatasource instance. Oracledatasource ODS=NewOracledatasource ();3. Set the desired propertiesifYou don ' t wantdefaultProperties. Different connection URLs should be used fordifferent JDBC drivers. Ods.setuser ("My_user"); Ods.setpassword ("My_password"); For the JDBC OCI driver:to make a bequeath connection, set URL As:ods.setURL ("Jdbc:oracle:oci:@"); To make a remote connection, set URL As:ods.setURL ("Jdbc:oracle:oci:@<database>"); where<database>is either a tnsentryname or a SQL*net name-value pair defined in Tnsnames.ora. For the JDBC Thin Driver, or Server-side Thin Driver:ods.setURL ("Jdbc:oracle:thin:@<database>"); where<database>is either a string of the form//or a tnsentryname. For the JDBC Server-side Internal Driver:ods.setURL ("JDBC:ORACLE:KPRB:"); Note that the trailing‘:‘is necessary. when you use the Server-side Internal Driver, you have connect to the database is executing in. You can also Do  This: Connection Conn=Neworacle.jdbc.OracleDriver (). DefaultConnection ();4. Open a connection to the database with getconnection () methods defined in Oracledatasourceclass. Connection Conn=ods.getconnection ();-----------------------------------------------------------------------

Java links oracle11g R2

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.