The JDBC connection URL of oracle11g is different from the previous version.

Source: Internet
Author: User

After oracle11g is installed today, a JDBC test program is written and cannot be connected all the time!

Why cannot be found

Later, I read the readme.txt document in the ghost Installation File! This version actually changes the URL access method:

Some useful hints in using the JDBC drivers
-------------------------------------------

Please refer to "JDBC developer's guide and reference" For details
Regarding usage of Oracle's JDBC drivers. This section only offers
Useful hints. These hints are not meant to be exhaustive.

These are a few simple things that you shoshould do in your JDBC program:

1. Import the necessary JDBC classes in your programs that use JDBC.
For example:

Import java. SQL .*;
Import java. Math. *; // if needed

To use oracledatasource, you need to do:
Import oracle. JDBC. Pool. oracledatasource;

2. Create an oracledatasource instance.

Oracledatasource ODS = new oracledatasource ();

3. Set the desired properties if you don't want to use
Default properties. Different connection URLs shocould be
Used for different JDBC drivers.

ODS. setuser ("my_user ");
ODS. setpassword ("my_password ");

For the jdbc oci driver:
To make a bequeath connection, set URL:
ODS. seturl ("JDBC: oracle: OCI :@");

To make a remote connection, set URL:
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
// <Host>: <port>/<SERVICE_NAME>, or a SQL * Net name-value pair,
Or a tnsentryname.

For the JDBC server-side internal DRIVER:
ODS. seturl ("JDBC: oracle: kprb :");

Note that the trailing ':' is necessary. When you use
Server-side internal driver, you always connect to
Database you are executing in. You can also do this:

Connection conn =
New Oracle. JDBC. oracledriver (). defaultconnection ();

4. open a connection to the database with getconnection ()
Methods defined in oracledatasource class.

Connection conn = ODS. getconnection ();

------------------------------------------------------------------------

You still have a good look at the original documentation!

But I still don't understand why it suddenly changes?

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.